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
|
|
|
//===----------------------------------------------------------------------===//
|
2009-03-26 11:35:11 +08:00
|
|
|
// Symbol iteration within an SVal.
|
2008-02-15 07:25:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2009-03-26 11:35:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2009-03-04 06:06:47 +08:00
|
|
|
/// getAsLocSymbol - If this SVal is a location (subclasses Loc) and
|
|
|
|
/// wraps a symbol, return that SymbolRef. Otherwise return a SymbolRef
|
|
|
|
/// where 'isValid()' returns false.
|
|
|
|
SymbolRef SVal::getAsLocSymbol() const {
|
|
|
|
if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) {
|
|
|
|
const MemRegion *R = X->getRegion();
|
|
|
|
|
|
|
|
while (R) {
|
|
|
|
// Blast through region views.
|
|
|
|
if (const TypedViewRegion *View = dyn_cast<TypedViewRegion>(R)) {
|
|
|
|
R = View->getSuperRegion();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
|
|
|
|
return SymR->getSymbol();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-26 11:35:11 +08:00
|
|
|
return 0;
|
2009-03-04 06:06:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getAsSymbol - If this Sval wraps a symbol return that SymbolRef.
|
|
|
|
/// Otherwise return a SymbolRef where 'isValid()' returns false.
|
|
|
|
SymbolRef SVal::getAsSymbol() const {
|
|
|
|
if (const nonloc::SymbolVal *X = dyn_cast<nonloc::SymbolVal>(this))
|
|
|
|
return X->getSymbol();
|
|
|
|
|
2009-03-26 11:35:11 +08:00
|
|
|
if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
|
|
|
|
if (SymbolRef Y = dyn_cast<SymbolData>(X->getSymbolicExpression()))
|
|
|
|
return Y;
|
|
|
|
|
2009-03-04 06:06:47 +08:00
|
|
|
return getAsLocSymbol();
|
|
|
|
}
|
|
|
|
|
2009-03-26 11:35:11 +08:00
|
|
|
/// getAsSymbolicExpression - If this Sval wraps a symbolic expression then
|
|
|
|
/// return that expression. Otherwise return NULL.
|
|
|
|
const SymExpr *SVal::getAsSymbolicExpression() const {
|
|
|
|
if (const nonloc::SymExprVal *X = dyn_cast<nonloc::SymExprVal>(this))
|
|
|
|
return X->getSymbolicExpression();
|
|
|
|
|
|
|
|
return getAsSymbol();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const {
|
|
|
|
return itr == X.itr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SVal::symbol_iterator::operator!=(const symbol_iterator &X) const {
|
|
|
|
return itr != X.itr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SVal::symbol_iterator::symbol_iterator(const SymExpr *SE) {
|
|
|
|
itr.push_back(SE);
|
|
|
|
while (!isa<SymbolData>(itr.back())) expand();
|
|
|
|
}
|
|
|
|
|
|
|
|
SVal::symbol_iterator& SVal::symbol_iterator::operator++() {
|
|
|
|
assert(!itr.empty() && "attempting to iterate on an 'end' iterator");
|
|
|
|
assert(isa<SymbolData>(itr.back()));
|
|
|
|
itr.pop_back();
|
|
|
|
if (!itr.empty())
|
|
|
|
while (!isa<SymbolData>(itr.back())) expand();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolRef SVal::symbol_iterator::operator*() {
|
|
|
|
assert(!itr.empty() && "attempting to dereference an 'end' iterator");
|
|
|
|
return cast<SymbolData>(itr.back());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVal::symbol_iterator::expand() {
|
|
|
|
const SymExpr *SE = itr.back();
|
|
|
|
itr.pop_back();
|
|
|
|
|
|
|
|
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SE)) {
|
|
|
|
itr.push_back(SIE->getLHS());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (const SymSymExpr *SSE = dyn_cast<SymSymExpr>(SE)) {
|
|
|
|
itr.push_back(SSE->getLHS());
|
|
|
|
itr.push_back(SSE->getRHS());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(false && "unhandled expansion case");
|
|
|
|
}
|
|
|
|
|
2008-10-31 02:01:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Other Iterators.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
nonloc::CompoundVal::iterator nonloc::CompoundVal::begin() const {
|
|
|
|
return getValue()->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const {
|
|
|
|
return getValue()->end();
|
|
|
|
}
|
|
|
|
|
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-31 01:53:23 +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
|
|
|
}
|
|
|
|
|
2009-04-09 02:51:08 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods for constructing SVals.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-10 00:46:55 +08:00
|
|
|
SVal ValueManager::makeZeroVal(QualType T) {
|
2009-04-09 02:51:08 +08:00
|
|
|
if (Loc::IsLocType(T))
|
|
|
|
return Loc::MakeNull(BasicVals);
|
|
|
|
|
|
|
|
if (T->isIntegerType())
|
|
|
|
return NonLoc::MakeVal(BasicVals, 0, T);
|
|
|
|
|
|
|
|
// FIXME: Handle floats.
|
|
|
|
// FIXME: Handle structs.
|
|
|
|
return UnknownVal();
|
|
|
|
}
|
|
|
|
|
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-12-20 14:32:12 +08:00
|
|
|
|
2009-04-11 02:11:44 +08:00
|
|
|
NonLoc ValueManager::makeNonLoc(SymbolRef sym) {
|
2008-12-20 14:32:12 +08:00
|
|
|
return nonloc::SymbolVal(sym);
|
2009-03-25 13:58:37 +08:00
|
|
|
}
|
|
|
|
|
2009-04-11 02:11:44 +08:00
|
|
|
NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
|
|
|
const APSInt& v, QualType T) {
|
2009-03-25 13:58:37 +08:00
|
|
|
// The Environment ensures we always get a persistent APSInt in
|
|
|
|
// BasicValueFactory, so we don't need to get the APSInt from
|
|
|
|
// BasicValueFactory again.
|
2009-03-26 11:35:11 +08:00
|
|
|
assert(!Loc::IsLocType(T));
|
|
|
|
return nonloc::SymExprVal(SymMgr.getSymIntExpr(lhs, op, v, T));
|
2009-03-25 13:58:37 +08:00
|
|
|
}
|
|
|
|
|
2009-04-11 02:11:44 +08:00
|
|
|
NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
|
|
|
|
const SymExpr *rhs, QualType T) {
|
2009-03-25 13:58:37 +08:00
|
|
|
assert(SymMgr.getType(lhs) == SymMgr.getType(rhs));
|
2009-03-26 11:35:11 +08:00
|
|
|
assert(!Loc::IsLocType(T));
|
|
|
|
return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
|
2008-12-20 14:32:12 +08:00
|
|
|
}
|
|
|
|
|
2009-01-30 08:08:43 +08:00
|
|
|
NonLoc NonLoc::MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
|
|
|
|
bool isUnsigned) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
|
2008-11-24 10:18:56 +08:00
|
|
|
}
|
2008-02-01 03:34:24 +08:00
|
|
|
|
2008-11-24 17:38:21 +08:00
|
|
|
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X,
|
|
|
|
unsigned BitWidth, bool isUnsigned) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
|
|
|
|
}
|
|
|
|
|
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-11-22 21:21:46 +08:00
|
|
|
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
|
|
|
|
bool isUnsigned) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned));
|
|
|
|
}
|
|
|
|
|
2008-11-24 17:38:21 +08:00
|
|
|
NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getValue(I));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-04-11 08:11:10 +08:00
|
|
|
NonLoc ValueManager::makeTruthVal(bool b, QualType T) {
|
|
|
|
return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
|
|
|
|
}
|
|
|
|
|
2008-10-31 01:44:46 +08:00
|
|
|
NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
|
2008-10-30 12:58:00 +08:00
|
|
|
BasicValueFactory& BasicVals) {
|
2008-10-31 01:44:46 +08:00
|
|
|
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
|
2008-10-30 12:58:00 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 06:22:44 +08:00
|
|
|
SVal ValueManager::getRValueSymbolVal(const MemRegion* R) {
|
Static analyzer: Remove a bunch of outdated SymbolData objects and
their associated APIs. We no longer need separate SymbolData objects
for fields, variables, etc. Instead, we now associated symbols with
the "rvalue" of a MemRegion (i.e., the value stored at that region).
Now we only have two kinds of SymbolData objects: SymbolRegionRValue
and SymbolConjured.
This cleanup also makes the distinction between a SymbolicRegion and a
symbolic value that is a location much clearer. A SymbolicRegion
represents a chunk of symbolic memory, while a symbolic location is
just a "pointer" with different possible values. Without any specific
knowledge, a symbolic location resolves (i.e., via a dereference) to a
SymbolicRegion. In the future, when we do better alias reasoning, a
symbolic location can become an alias for another location, thus
merging the constraints on the referred SymbolicRegion with the other
region.
llvm-svn: 62769
2009-01-23 02:23:34 +08:00
|
|
|
SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
|
|
|
|
|
2009-03-19 06:10:22 +08:00
|
|
|
if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
|
|
|
|
QualType T = TR->getRValueType(SymMgr.getContext());
|
2009-04-10 16:45:10 +08:00
|
|
|
|
|
|
|
// If T is of function pointer type, create a CodeTextRegion wrapping a
|
|
|
|
// symbol.
|
|
|
|
if (T->isFunctionPointerType()) {
|
|
|
|
return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
|
|
|
|
}
|
2009-03-19 06:10:22 +08:00
|
|
|
|
|
|
|
if (Loc::IsLocType(T))
|
2009-04-10 06:22:44 +08:00
|
|
|
return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
|
2008-05-01 06:48:21 +08:00
|
|
|
|
2009-03-19 06:10:22 +08:00
|
|
|
// Only handle integers for now.
|
2009-04-09 13:57:11 +08:00
|
|
|
if (T->isIntegerType() && T->isScalarType())
|
2009-04-11 02:11:44 +08:00
|
|
|
return makeNonLoc(sym);
|
2009-03-19 06:10:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return UnknownVal();
|
2008-11-19 19:03:17 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 06:22:44 +08:00
|
|
|
SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
|
2009-03-21 04:10:45 +08:00
|
|
|
QualType T = E->getType();
|
2009-04-09 13:57:11 +08:00
|
|
|
SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
|
|
|
|
|
2009-04-10 16:45:10 +08:00
|
|
|
// If T is of function pointer type, create a CodeTextRegion wrapping a
|
|
|
|
// symbol.
|
|
|
|
if (T->isFunctionPointerType()) {
|
|
|
|
return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
|
|
|
|
}
|
|
|
|
|
2009-04-09 13:57:11 +08:00
|
|
|
if (Loc::IsLocType(T))
|
2009-04-10 06:22:44 +08:00
|
|
|
return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
|
2009-04-09 13:57:11 +08:00
|
|
|
|
|
|
|
if (T->isIntegerType() && T->isScalarType())
|
2009-04-11 02:11:44 +08:00
|
|
|
return makeNonLoc(sym);
|
2009-03-21 04:10:45 +08:00
|
|
|
|
|
|
|
return UnknownVal();
|
|
|
|
}
|
|
|
|
|
2009-04-10 06:22:44 +08:00
|
|
|
SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
|
|
|
|
unsigned Count) {
|
|
|
|
|
2009-04-09 14:30:17 +08:00
|
|
|
SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
|
|
|
|
|
2009-04-10 16:45:10 +08:00
|
|
|
// If T is of function pointer type, create a CodeTextRegion wrapping a
|
|
|
|
// symbol.
|
|
|
|
if (T->isFunctionPointerType()) {
|
|
|
|
return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
|
|
|
|
}
|
|
|
|
|
2009-04-09 14:30:17 +08:00
|
|
|
if (Loc::IsLocType(T))
|
2009-04-10 06:22:44 +08:00
|
|
|
return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
|
2009-04-09 14:30:17 +08:00
|
|
|
|
|
|
|
if (T->isIntegerType() && T->isScalarType())
|
2009-04-11 02:11:44 +08:00
|
|
|
return makeNonLoc(sym);
|
2009-04-09 14:30:17 +08:00
|
|
|
|
|
|
|
return UnknownVal();
|
|
|
|
}
|
|
|
|
|
2009-04-10 16:45:10 +08:00
|
|
|
SVal ValueManager::getFunctionPointer(const FunctionDecl* FD) {
|
|
|
|
CodeTextRegion* R
|
|
|
|
= MemMgr.getCodeTextRegion(FD, Context.getPointerType(FD->getType()));
|
|
|
|
return Loc::MakeVal(R);
|
|
|
|
}
|
|
|
|
|
2008-10-31 01:44:46 +08:00
|
|
|
nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
|
|
|
|
unsigned Bits) {
|
|
|
|
return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
|
|
|
|
}
|
|
|
|
|
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-12-09 18:51:19 +08:00
|
|
|
Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); }
|
|
|
|
|
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
|
|
|
|
2009-04-09 02:51:08 +08:00
|
|
|
Loc Loc::MakeNull(BasicValueFactory &BasicVals) {
|
|
|
|
return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
|
|
|
|
}
|
|
|
|
|
2008-02-01 03:34:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pretty-Printing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-03-11 02:00:19 +08:00
|
|
|
void SVal::printStdErr() const { print(llvm::errs()); }
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
void SVal::print(std::ostream& Out) const {
|
2008-10-31 02:35:10 +08:00
|
|
|
llvm::raw_os_ostream out(Out);
|
|
|
|
print(out);
|
2008-02-01 03:34:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-24 14:00:12 +08:00
|
|
|
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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-03-26 11:35:11 +08:00
|
|
|
case nonloc::SymExprValKind: {
|
|
|
|
const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this);
|
|
|
|
const SymExpr *SE = C.getSymbolicExpression();
|
|
|
|
Out << SE;
|
2008-10-24 14:00:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nonloc::LocAsIntegerKind: {
|
|
|
|
const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
|
|
|
|
C.getLoc().print(Out);
|
|
|
|
Out << " [as " << C.getNumBits() << " bit integer]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-31 02:01:28 +08:00
|
|
|
case nonloc::CompoundValKind: {
|
|
|
|
const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this);
|
2008-10-31 02:35:10 +08:00
|
|
|
Out << " {";
|
|
|
|
bool first = true;
|
|
|
|
for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) {
|
|
|
|
if (first) { Out << ' '; first = false; }
|
|
|
|
else Out << ", ";
|
2008-10-31 02:01:28 +08:00
|
|
|
(*I).print(Out);
|
2008-10-31 02:35:10 +08:00
|
|
|
}
|
2008-10-31 02:01:28 +08:00
|
|
|
Out << " }";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-24 14:00:12 +08:00
|
|
|
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::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;
|
|
|
|
}
|
|
|
|
}
|