2008-02-01 03:34:24 +08:00
|
|
|
//= RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-10-17 13:57:07 +08:00
|
|
|
// This file defines SVal, Loc, and NonLoc, classes that represent
|
2008-02-01 03:34:24 +08:00
|
|
|
// abstract r-values for use with path-sensitive value tracking.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-04 13:50:14 +08:00
|
|
|
#include "clang/Analysis/PathSensitive/GRState.h"
|
2008-08-11 13:35:13 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2008-02-16 09:12:31 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using llvm::dyn_cast;
|
|
|
|
using llvm::cast;
|
|
|
|
using llvm::APSInt;
|
|
|
|
|
2008-02-15 07:25:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Symbol Iteration.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
SVal::symbol_iterator SVal::symbol_begin() const {
|
2008-04-30 06:17:41 +08:00
|
|
|
|
|
|
|
// FIXME: This is a rat's nest. Cleanup.
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (isa<loc::SymbolVal>(this))
|
2008-02-22 02:02:17 +08:00
|
|
|
return (symbol_iterator) (&Data);
|
2008-10-17 13:57:07 +08:00
|
|
|
else if (isa<nonloc::SymbolVal>(this))
|
2008-02-22 02:02:17 +08:00
|
|
|
return (symbol_iterator) (&Data);
|
2008-10-17 13:57:07 +08:00
|
|
|
else if (isa<nonloc::SymIntConstraintVal>(this)) {
|
2008-02-22 02:02:17 +08:00
|
|
|
const SymIntConstraint& C =
|
2008-10-17 13:57:07 +08:00
|
|
|
cast<nonloc::SymIntConstraintVal>(this)->getConstraint();
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
return (symbol_iterator) &C.getSymbol();
|
2008-02-15 07:25:54 +08:00
|
|
|
}
|
2008-10-17 13:57:07 +08:00
|
|
|
else if (isa<nonloc::LocAsInteger>(this)) {
|
|
|
|
const nonloc::LocAsInteger& V = cast<nonloc::LocAsInteger>(*this);
|
|
|
|
return V.getPersistentLoc().symbol_begin();
|
2008-04-23 05:10:18 +08:00
|
|
|
}
|
2008-10-17 08:51:01 +08:00
|
|
|
|
|
|
|
// FIXME: We need to iterate over the symbols of regions.
|
|
|
|
|
2008-02-15 07:25:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
SVal::symbol_iterator SVal::symbol_end() const {
|
2008-02-15 07:25:54 +08:00
|
|
|
symbol_iterator X = symbol_begin();
|
|
|
|
return X ? X+1 : NULL;
|
|
|
|
}
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-07-18 23:54:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Useful predicates.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
bool SVal::isZeroConstant() const {
|
|
|
|
if (isa<loc::ConcreteInt>(*this))
|
|
|
|
return cast<loc::ConcreteInt>(*this).getValue() == 0;
|
|
|
|
else if (isa<nonloc::ConcreteInt>(*this))
|
|
|
|
return cast<nonloc::ConcreteInt>(*this).getValue() == 0;
|
2008-07-18 23:54:51 +08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-10-17 13:57:07 +08:00
|
|
|
// Transfer function dispatch for Non-Locs.
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
SVal nonloc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals,
|
2008-07-18 23:59:33 +08:00
|
|
|
BinaryOperator::Opcode Op,
|
2008-10-17 13:57:07 +08:00
|
|
|
const nonloc::ConcreteInt& R) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-07-18 23:59:33 +08:00
|
|
|
const llvm::APSInt* X =
|
|
|
|
BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
|
2008-02-29 04:32:03 +08:00
|
|
|
|
|
|
|
if (X)
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::ConcreteInt(*X);
|
2008-02-29 04:32:03 +08:00
|
|
|
else
|
|
|
|
return UndefinedVal();
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bitwise-Complement.
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
nonloc::ConcreteInt
|
|
|
|
nonloc::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const {
|
2008-03-08 04:13:31 +08:00
|
|
|
return BasicVals.getValue(~getValue());
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unary Minus.
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
nonloc::ConcreteInt
|
|
|
|
nonloc::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const {
|
2008-02-07 06:50:25 +08:00
|
|
|
assert (U->getType() == U->getSubExpr()->getType());
|
|
|
|
assert (U->getType()->isIntegerType());
|
2008-03-08 04:13:31 +08:00
|
|
|
return BasicVals.getValue(-getValue());
|
2008-02-05 00:58:30 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-10-17 13:57:07 +08:00
|
|
|
// Transfer function dispatch for Locs.
|
2008-02-07 06:50:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-05 00:58:30 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
SVal
|
|
|
|
loc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op,
|
|
|
|
const loc::ConcreteInt& R) const {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
|
|
|
|
(Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
|
|
|
|
|
2008-03-08 04:13:31 +08:00
|
|
|
const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
|
2008-02-29 04:32:03 +08:00
|
|
|
|
|
|
|
if (X)
|
2008-10-17 13:57:07 +08:00
|
|
|
return loc::ConcreteInt(*X);
|
2008-02-29 04:32:03 +08:00
|
|
|
else
|
|
|
|
return UndefinedVal();
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
NonLoc Loc::EQ(BasicValueFactory& BasicVals, const Loc& R) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
2008-10-17 13:57:07 +08:00
|
|
|
assert(false && "EQ not implemented for this Loc.");
|
2008-02-22 02:02:17 +08:00
|
|
|
break;
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::ConcreteIntKind:
|
|
|
|
if (isa<loc::ConcreteInt>(R)) {
|
|
|
|
bool b = cast<loc::ConcreteInt>(this)->getValue() ==
|
|
|
|
cast<loc::ConcreteInt>(R).getValue();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-10-17 13:57:07 +08:00
|
|
|
else if (isa<loc::SymbolVal>(R)) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
const SymIntConstraint& C =
|
2008-10-17 13:57:07 +08:00
|
|
|
BasicVals.getConstraint(cast<loc::SymbolVal>(R).getSymbol(),
|
2008-02-22 02:02:17 +08:00
|
|
|
BinaryOperator::EQ,
|
2008-10-17 13:57:07 +08:00
|
|
|
cast<loc::ConcreteInt>(this)->getValue());
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::SymIntConstraintVal(C);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::SymbolValKind: {
|
|
|
|
if (isa<loc::ConcreteInt>(R)) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-10-17 13:57:07 +08:00
|
|
|
BasicVals.getConstraint(cast<loc::SymbolVal>(this)->getSymbol(),
|
2008-02-22 02:02:17 +08:00
|
|
|
BinaryOperator::EQ,
|
2008-10-17 13:57:07 +08:00
|
|
|
cast<loc::ConcreteInt>(R).getValue());
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::SymIntConstraintVal(C);
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (!isa<loc::SymbolVal>(R) && "FIXME: Implement unification.");
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
break;
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::MemRegionKind:
|
|
|
|
if (isa<loc::MemRegionVal>(R)) {
|
|
|
|
bool b = cast<loc::MemRegionVal>(*this) == cast<loc::MemRegionVal>(R);
|
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, false);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
NonLoc Loc::NE(BasicValueFactory& BasicVals, const Loc& R) const {
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
|
|
|
default:
|
2008-10-17 13:57:07 +08:00
|
|
|
assert(false && "NE not implemented for this Loc.");
|
2008-02-22 02:02:17 +08:00
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::ConcreteIntKind:
|
|
|
|
if (isa<loc::ConcreteInt>(R)) {
|
|
|
|
bool b = cast<loc::ConcreteInt>(this)->getValue() !=
|
|
|
|
cast<loc::ConcreteInt>(R).getValue();
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, b);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-10-17 13:57:07 +08:00
|
|
|
else if (isa<loc::SymbolVal>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-10-17 13:57:07 +08:00
|
|
|
BasicVals.getConstraint(cast<loc::SymbolVal>(R).getSymbol(),
|
2008-02-06 07:08:41 +08:00
|
|
|
BinaryOperator::NE,
|
2008-10-17 13:57:07 +08:00
|
|
|
cast<loc::ConcreteInt>(this)->getValue());
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::SymIntConstraintVal(C);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
break;
|
2008-02-01 14:36:40 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::SymbolValKind: {
|
|
|
|
if (isa<loc::ConcreteInt>(R)) {
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
const SymIntConstraint& C =
|
2008-10-17 13:57:07 +08:00
|
|
|
BasicVals.getConstraint(cast<loc::SymbolVal>(this)->getSymbol(),
|
2008-02-06 07:08:41 +08:00
|
|
|
BinaryOperator::NE,
|
2008-10-17 13:57:07 +08:00
|
|
|
cast<loc::ConcreteInt>(R).getValue());
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::SymIntConstraintVal(C);
|
2008-02-06 07:08:41 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (!isa<loc::SymbolVal>(R) && "FIXME: Implement sym !=.");
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::MemRegionKind:
|
|
|
|
if (isa<loc::MemRegionVal>(R)) {
|
|
|
|
bool b = cast<loc::MemRegionVal>(*this)==cast<loc::MemRegionVal>(R);
|
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, b);
|
2008-02-22 02:02:17 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
break;
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return NonLoc::MakeIntTruthVal(BasicVals, true);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-10-17 13:57:07 +08:00
|
|
|
// Utility methods for constructing Non-Locs.
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getValue(X, T));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
|
2008-02-22 02:02:17 +08:00
|
|
|
I->getType()->isUnsignedIntegerType())));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
QualType T = D->getType();
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (Loc::IsLocType(T))
|
|
|
|
return loc::SymbolVal(SymMgr.getSymbol(D));
|
2008-05-01 06:48:21 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
return nonloc::SymbolVal(SymMgr.getSymbol(D));
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-02-13 05:37:56 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-10-17 13:57:07 +08:00
|
|
|
// Utility methods for constructing Locs.
|
2008-02-13 05:37:56 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
Loc Loc::MakeVal(AddrLabelExpr* E) { return loc::GotoLabel(E->getLabel()); }
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pretty-Printing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
void SVal::printStdErr() const { print(*llvm::cerr.stream()); }
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
void SVal::print(std::ostream& Out) const {
|
2008-02-13 05:37:56 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getBaseKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-08 11:02:48 +08:00
|
|
|
case UnknownKind:
|
2008-02-22 02:02:17 +08:00
|
|
|
Out << "Invalid"; break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case NonLocKind:
|
|
|
|
cast<NonLoc>(this)->print(Out); break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case LocKind:
|
|
|
|
cast<Loc>(this)->print(Out); break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
case UndefinedKind:
|
|
|
|
Out << "Undefined"; break;
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
default:
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (false && "Invalid SVal.");
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
switch (Op) {
|
|
|
|
case BinaryOperator::Mul: Out << '*' ; break;
|
|
|
|
case BinaryOperator::Div: Out << '/' ; break;
|
|
|
|
case BinaryOperator::Rem: Out << '%' ; break;
|
|
|
|
case BinaryOperator::Add: Out << '+' ; break;
|
|
|
|
case BinaryOperator::Sub: Out << '-' ; break;
|
2008-02-16 06:09:30 +08:00
|
|
|
case BinaryOperator::Shl: Out << "<<" ; break;
|
|
|
|
case BinaryOperator::Shr: Out << ">>" ; break;
|
2008-02-22 02:02:17 +08:00
|
|
|
case BinaryOperator::LT: Out << "<" ; break;
|
|
|
|
case BinaryOperator::GT: Out << '>' ; break;
|
|
|
|
case BinaryOperator::LE: Out << "<=" ; break;
|
|
|
|
case BinaryOperator::GE: Out << ">=" ; break;
|
|
|
|
case BinaryOperator::EQ: Out << "==" ; break;
|
|
|
|
case BinaryOperator::NE: Out << "!=" ; break;
|
|
|
|
case BinaryOperator::And: Out << '&' ; break;
|
|
|
|
case BinaryOperator::Xor: Out << '^' ; break;
|
|
|
|
case BinaryOperator::Or: Out << '|' ; break;
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
default: assert(false && "Not yet implemented.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
void NonLoc::print(std::ostream& Out) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
switch (getSubKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case nonloc::ConcreteIntKind:
|
|
|
|
Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
|
2008-02-07 06:50:25 +08:00
|
|
|
Out << 'U';
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case nonloc::SymbolValKind:
|
|
|
|
Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
2008-02-06 07:08:41 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case nonloc::SymIntConstraintValKind: {
|
|
|
|
const nonloc::SymIntConstraintVal& C =
|
|
|
|
*cast<nonloc::SymIntConstraintVal>(this);
|
2008-02-06 07:08:41 +08:00
|
|
|
|
|
|
|
Out << '$' << C.getConstraint().getSymbol() << ' ';
|
|
|
|
printOpcode(Out, C.getConstraint().getOpcode());
|
2008-08-24 06:23:37 +08:00
|
|
|
Out << ' ' << C.getConstraint().getInt().getZExtValue();
|
2008-02-07 06:50:25 +08:00
|
|
|
|
|
|
|
if (C.getConstraint().getInt().isUnsigned())
|
|
|
|
Out << 'U';
|
|
|
|
|
2008-02-06 07:08:41 +08:00
|
|
|
break;
|
2008-04-23 05:10:18 +08:00
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case nonloc::LocAsIntegerKind: {
|
|
|
|
const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
|
|
|
|
C.getLoc().print(Out);
|
2008-04-23 05:10:18 +08:00
|
|
|
Out << " [as " << C.getNumBits() << " bit integer]";
|
|
|
|
break;
|
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
|
|
|
default:
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (false && "Pretty-printed not implemented for this NonLoc.");
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
void Loc::print(std::ostream& Out) const {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-01 14:36:40 +08:00
|
|
|
switch (getSubKind()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::ConcreteIntKind:
|
|
|
|
Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
|
|
|
|
<< " (Loc)";
|
2008-02-01 14:36:40 +08:00
|
|
|
break;
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::SymbolValKind:
|
|
|
|
Out << '$' << cast<loc::SymbolVal>(this)->getSymbol();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
2008-02-13 05:37:56 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::GotoLabelKind:
|
2008-02-13 05:37:56 +08:00
|
|
|
Out << "&&"
|
2008-10-17 13:57:07 +08:00
|
|
|
<< cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
|
2008-02-13 05:37:56 +08:00
|
|
|
break;
|
2008-02-06 12:31:33 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::MemRegionKind:
|
|
|
|
Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
|
2008-02-19 09:44:53 +08:00
|
|
|
break;
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
case loc::FuncValKind:
|
2008-02-19 09:44:53 +08:00
|
|
|
Out << "function "
|
2008-10-17 13:57:07 +08:00
|
|
|
<< cast<loc::FuncVal>(this)->getDecl()->getIdentifier()->getName();
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (false && "Pretty-printing not implemented for this Loc.");
|
2008-02-01 03:34:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-10-24 14:00:12 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pretty-Printing with llvm::raw_ostream.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void SVal::print(llvm::raw_ostream& Out) const {
|
|
|
|
|
|
|
|
switch (getBaseKind()) {
|
|
|
|
|
|
|
|
case UnknownKind:
|
|
|
|
Out << "Invalid"; break;
|
|
|
|
|
|
|
|
case NonLocKind:
|
|
|
|
cast<NonLoc>(this)->print(Out); break;
|
|
|
|
|
|
|
|
case LocKind:
|
|
|
|
cast<Loc>(this)->print(Out); break;
|
|
|
|
|
|
|
|
case UndefinedKind:
|
|
|
|
Out << "Undefined"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Invalid SVal.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printOpcode(llvm::raw_ostream& Out, BinaryOperator::Opcode Op) {
|
|
|
|
|
|
|
|
switch (Op) {
|
|
|
|
case BinaryOperator::Mul: Out << '*' ; break;
|
|
|
|
case BinaryOperator::Div: Out << '/' ; break;
|
|
|
|
case BinaryOperator::Rem: Out << '%' ; break;
|
|
|
|
case BinaryOperator::Add: Out << '+' ; break;
|
|
|
|
case BinaryOperator::Sub: Out << '-' ; break;
|
|
|
|
case BinaryOperator::Shl: Out << "<<" ; break;
|
|
|
|
case BinaryOperator::Shr: Out << ">>" ; break;
|
|
|
|
case BinaryOperator::LT: Out << "<" ; break;
|
|
|
|
case BinaryOperator::GT: Out << '>' ; break;
|
|
|
|
case BinaryOperator::LE: Out << "<=" ; break;
|
|
|
|
case BinaryOperator::GE: Out << ">=" ; break;
|
|
|
|
case BinaryOperator::EQ: Out << "==" ; break;
|
|
|
|
case BinaryOperator::NE: Out << "!=" ; break;
|
|
|
|
case BinaryOperator::And: Out << '&' ; break;
|
|
|
|
case BinaryOperator::Xor: Out << '^' ; break;
|
|
|
|
case BinaryOperator::Or: Out << '|' ; break;
|
|
|
|
|
|
|
|
default: assert(false && "Not yet implemented.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonLoc::print(llvm::raw_ostream& Out) const {
|
|
|
|
|
|
|
|
switch (getSubKind()) {
|
|
|
|
|
|
|
|
case nonloc::ConcreteIntKind:
|
|
|
|
Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
|
|
|
|
|
|
|
|
if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
|
|
|
|
Out << 'U';
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nonloc::SymbolValKind:
|
|
|
|
Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nonloc::SymIntConstraintValKind: {
|
|
|
|
const nonloc::SymIntConstraintVal& C =
|
|
|
|
*cast<nonloc::SymIntConstraintVal>(this);
|
|
|
|
|
|
|
|
Out << '$' << C.getConstraint().getSymbol() << ' ';
|
|
|
|
printOpcode(Out, C.getConstraint().getOpcode());
|
|
|
|
Out << ' ' << C.getConstraint().getInt().getZExtValue();
|
|
|
|
|
|
|
|
if (C.getConstraint().getInt().isUnsigned())
|
|
|
|
Out << 'U';
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nonloc::LocAsIntegerKind: {
|
|
|
|
const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
|
|
|
|
C.getLoc().print(Out);
|
|
|
|
Out << " [as " << C.getNumBits() << " bit integer]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Pretty-printed not implemented for this NonLoc.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Loc::print(llvm::raw_ostream& Out) const {
|
|
|
|
|
|
|
|
switch (getSubKind()) {
|
|
|
|
|
|
|
|
case loc::ConcreteIntKind:
|
|
|
|
Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
|
|
|
|
<< " (Loc)";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case loc::SymbolValKind:
|
|
|
|
Out << '$' << cast<loc::SymbolVal>(this)->getSymbol();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case loc::GotoLabelKind:
|
|
|
|
Out << "&&"
|
|
|
|
<< cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case loc::MemRegionKind:
|
|
|
|
Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case loc::FuncValKind:
|
|
|
|
Out << "function "
|
|
|
|
<< cast<loc::FuncVal>(this)->getDecl()->getIdentifier()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert (false && "Pretty-printing not implemented for this Loc.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|