inline bool operator==(const SVal& R) const {
return getRawKind() == R.getRawKind() && Data == R.Data;
}
-
-
+
inline bool operator!=(const SVal& R) const {
return !(*this == R);
}
/// GetRValueSymbolVal - make a unique symbol for value of R.
static SVal GetRValueSymbolVal(SymbolManager& SymMgr, const MemRegion* R);
-
inline bool isUnknown() const {
return getRawKind() == UnknownKind;
}
bool isZeroConstant() const;
+ /// 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 getAsLocSymbol() const;
+
+ /// getAsSymbol - If this Sval wraps a symbol return that SymbolRef.
+ /// Otherwise return a SymbolRef where 'isValid()' returns false.
+ SymbolRef getAsSymbol() const;
+
void print(std::ostream& OS) const;
void print(llvm::raw_ostream& OS) const;
void printStdErr() const;
class SymbolVal : public NonLoc {
public:
- SymbolVal(unsigned SymID)
- : NonLoc(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
+ SymbolVal(SymbolRef SymID)
+ : NonLoc(SymbolValKind,
+ reinterpret_cast<void*>((uintptr_t) SymID.getNumber())) {}
SymbolRef getSymbol() const {
return (SymbolRef) reinterpret_cast<uintptr_t>(Data);
class SymbolVal : public Loc {
public:
- SymbolVal(unsigned SymID)
- : Loc(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
+ SymbolVal(SymbolRef SymID)
+ : Loc(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID.getNumber())){}
SymbolRef getSymbol() const {
return (SymbolRef) reinterpret_cast<uintptr_t>(Data);
public:
SymbolRef() : Data(~0U - 2) {}
SymbolRef(unsigned x) : Data(x) {}
-
- bool isInitialized() const { return Data != (unsigned) (~0U - 2); }
- operator unsigned() const { return getNumber(); }
- unsigned getNumber() const { assert (isInitialized()); return Data; }
+
+ bool isValid() const { return Data != (unsigned) (~0U - 2); }
+ unsigned getNumber() const { assert (isValid()); return Data; }
+ bool operator<(const SymbolRef& X) const { return Data < X.Data; }
+ bool operator>(const SymbolRef& X) const { return Data > X.Data; }
bool operator==(const SymbolRef& X) const { return Data == X.Data; }
bool operator!=(const SymbolRef& X) const { return Data != X.Data; }
-
- void print(llvm::raw_ostream& os) const;
-
+
void Profile(llvm::FoldingSetNodeID& ID) const {
- assert (isInitialized());
+ assert (isValid());
ID.AddInteger(Data);
}
};
-
} // end clang namespace
namespace llvm {
- template <> struct DenseMapInfo<clang::SymbolRef> {
- static inline clang::SymbolRef getEmptyKey() {
- return clang::SymbolRef(~0U);
- }
- static inline clang::SymbolRef getTombstoneKey() {
- return clang::SymbolRef(~0U - 1);
- }
- static unsigned getHashValue(clang::SymbolRef X) {
- return X.getNumber();
- }
- static bool isEqual(clang::SymbolRef X, clang::SymbolRef Y) {
- return X.getNumber() == Y.getNumber();
- }
- static bool isPod() { return true; }
- };
+ llvm::raw_ostream& operator<<(llvm::raw_ostream& Out, clang::SymbolRef Sym);
+}
+namespace std {
+ std::ostream& operator<<(std::ostream& Out, clang::SymbolRef Sym);
+}
+
+namespace llvm {
+template <> struct DenseMapInfo<clang::SymbolRef> {
+ static inline clang::SymbolRef getEmptyKey() {
+ return clang::SymbolRef(~0U);
+ }
+ static inline clang::SymbolRef getTombstoneKey() {
+ return clang::SymbolRef(~0U - 1);
+ }
+ static unsigned getHashValue(clang::SymbolRef X) {
+ return X.getNumber();
+ }
+ static bool isEqual(clang::SymbolRef X, clang::SymbolRef Y) {
+ return X == Y;
+ }
+ static bool isPod() { return true; }
+};
}
// SymbolData: Used to record meta data about symbols.
for (ExprIterator I = arg_beg; I != arg_end; ++I, ++idx) {
SVal V = state.GetSVal(*I);
- if (isa<loc::SymbolVal>(V)) {
- SymbolRef Sym = cast<loc::SymbolVal>(V).getSymbol();
+ SymbolRef Sym = V.getAsLocSymbol();
+ if (Sym.isValid())
if (RefBindings::data_type* T = state.get<RefBindings>(Sym)) {
state = Update(state, Sym, *T, GetArgE(Summ, idx), hasErr);
if (hasErr) {
ErrorExpr = *I;
ErrorSym = Sym;
break;
- }
+ }
+ continue;
}
- }
- else if (isa<Loc>(V)) {
- if (loc::MemRegionVal* MR = dyn_cast<loc::MemRegionVal>(&V)) {
+ if (isa<Loc>(V)) {
+ if (loc::MemRegionVal* MR = dyn_cast<loc::MemRegionVal>(&V)) {
if (GetArgE(Summ, idx) == DoNothingByRef)
continue;
R = dyn_cast<TypedRegion>(ATR->getSuperRegion());
}
- if (R) {
-
+ if (R) {
// Is the invalidated variable something that we were tracking?
- SVal X = state.GetSVal(Loc::MakeVal(R));
-
- if (isa<loc::SymbolVal>(X)) {
- SymbolRef Sym = cast<loc::SymbolVal>(X).getSymbol();
+ SymbolRef Sym = state.GetSVal(Loc::MakeVal(R)).getAsLocSymbol();
+ if (Sym.isValid())
state = state.remove<RefBindings>(Sym);
- }
// Set the value of the variable to be a conjured symbol.
unsigned Count = Builder.getCurrentBlockCount();
// Evaluate the effect on the message receiver.
if (!ErrorExpr && Receiver) {
- SVal V = state.GetSVal(Receiver);
- if (isa<loc::SymbolVal>(V)) {
- SymbolRef Sym = cast<loc::SymbolVal>(V).getSymbol();
+ SymbolRef Sym = state.GetSVal(Receiver).getAsLocSymbol();
+ if (Sym.isValid()) {
if (const RefVal* T = state.get<RefBindings>(Sym)) {
state = Update(state, Sym, *T, GetReceiverE(Summ), hasErr);
if (hasErr) {
// FIXME: Wouldn't it be great if this code could be reduced? It's just
// a chain of lookups.
const GRState* St = Builder.GetState(Pred);
- SVal V = Eng.getStateManager().GetSVal(St, Receiver );
+ SVal V = Eng.getStateManager().GetSVal(St, Receiver);
- if (isa<loc::SymbolVal>(V)) {
- SymbolRef Sym = cast<loc::SymbolVal>(V).getSymbol();
-
+ SymbolRef Sym = V.getAsLocSymbol();
+ if (Sym.isValid()) {
if (const RefVal* T = St->get<RefBindings>(Sym)) {
QualType Ty = T->getType();
ExplodedNode<GRState>* Pred) {
Expr* RetE = S->getRetValue();
- if (!RetE) return;
+ if (!RetE)
+ return;
GRStateRef state(Builder.GetState(Pred), Eng.getStateManager());
- SVal V = state.GetSVal(RetE);
+ SymbolRef Sym = state.GetSVal(RetE).getAsLocSymbol();
- if (!isa<loc::SymbolVal>(V))
+ if (!Sym.isValid())
return;
-
+
// Get the reference count binding (if any).
- SymbolRef Sym = cast<loc::SymbolVal>(V).getSymbol();
const RefVal* T = state.get<RefBindings>(Sym);
if (!T)
for (CallExpr::arg_iterator AI=CE->arg_begin(), AE=CE->arg_end();
AI!=AE; ++AI, ++i) {
- // Retrieve the value of the arugment.
- SVal X = CurrSt.GetSVal(*AI);
-
- // Is it the symbol we're interested in?
- if (!isa<loc::SymbolVal>(X) ||
- Sym != cast<loc::SymbolVal>(X).getSymbol())
+ // Retrieve the value of the argument. Is it the symbol
+ // we are interested in?
+ if (CurrSt.GetSVal(*AI).getAsLocSymbol() != Sym)
continue;
-
+
// We have an argument. Get the effect!
AEffects.push_back(Summ->getArg(i));
}
}
else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(S)) {
- if (Expr *receiver = ME->getReceiver()) {
- SVal RetV = CurrSt.GetSVal(receiver);
- if (isa<loc::SymbolVal>(RetV) &&
- Sym == cast<loc::SymbolVal>(RetV).getSymbol()) {
+ if (Expr *receiver = ME->getReceiver())
+ if (CurrSt.GetSVal(receiver).getAsLocSymbol() == Sym) {
// The symbol we are tracking is the receiver.
AEffects.push_back(Summ->getReceiverEffect());
}
- }
}
}
// Add the range by scanning the children of the statement for any bindings
// to Sym.
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
- if (Expr* Exp = dyn_cast_or_null<Expr>(*I)) {
- SVal X = CurrSt.GetSVal(Exp);
- if (loc::SymbolVal* SV = dyn_cast<loc::SymbolVal>(&X))
- if (SV->getSymbol() == Sym) {
- P->addRange(Exp->getSourceRange());
- break;
- }
- }
+ if (Expr* Exp = dyn_cast_or_null<Expr>(*I))
+ if (CurrSt.GetSVal(Exp).getAsLocSymbol() == Sym) {
+ P->addRange(Exp->getSourceRange());
+ break;
+ }
return P;
}
FindUniqueBinding(SymbolRef sym) : Sym(sym), Binding(0), First(true) {}
bool HandleBinding(StoreManager& SMgr, Store store, MemRegion* R, SVal val) {
- if (const loc::SymbolVal* SV = dyn_cast<loc::SymbolVal>(&val)) {
- if (SV->getSymbol() != Sym)
- return true;
- }
- else if (const nonloc::SymbolVal* SV=dyn_cast<nonloc::SymbolVal>(&val)) {
- if (SV->getSymbol() != Sym)
- return true;
- }
- else
+ SymbolRef SymV = val.getAsSymbol();
+
+ if (!SymV.isValid() || SymV != Sym)
return true;
-
+
if (Binding) {
First = false;
return false;
bool foundSymbol = false;
// First check if 'S' itself binds to the symbol.
- if (Expr *Ex = dyn_cast<Expr>(S)) {
- SVal X = state.GetSVal(Ex);
- if (isa<loc::SymbolVal>(X) &&
- cast<loc::SymbolVal>(X).getSymbol() == Sym)
+ if (Expr *Ex = dyn_cast<Expr>(S))
+ if (state.GetSVal(Ex).getAsLocSymbol() == Sym)
foundSymbol = true;
- }
if (!foundSymbol)
for (Stmt::child_iterator I=S->child_begin(), E=S->child_end();
I!=E; ++I)
if (Expr *Ex = dyn_cast_or_null<Expr>(*I)) {
SVal X = state.GetSVal(Ex);
- if (isa<loc::SymbolVal>(X) &&
- cast<loc::SymbolVal>(X).getSymbol() == Sym){
+ if (X.getAsLocSymbol() == Sym) {
foundSymbol = true;
break;
}
bool hasLeak = false;
std::pair<GRStateRef, bool> X =
- HandleSymbolDeath(Eng.getStateManager(), St, CodeDecl,
- (*I).first, (*I).second, hasLeak);
+ HandleSymbolDeath(Eng.getStateManager(), St, CodeDecl,
+ (*I).first, (*I).second, hasLeak);
St = X.first;
if (hasLeak) Leaked.push_back(std::make_pair((*I).first, X.second));