From: Ted Kremenek Date: Mon, 28 Jan 2008 22:09:13 +0000 (+0000) Subject: Some additional cleanups with method names. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd03f1d66d62434244deaa435fbbed3174edcf01;p=clang Some additional cleanups with method names. Renamed ExprValue to RValue, as all expression values are RValues, and this keeps with the C terminology (renamed old "RValue" class to "NonLValue"). Introduced "ConcreteInt", a class that represents a concrete, integer constant as an RValue. Temporarily removed classes to represent set of possible constants and set of != constants. Will replace with a more general class representing a set of constraints. Added some foundational code to track "symbolic" values, which are used to accrue constraints on an abstract value that is shared between multiple variables. e.g: x = y; // at this point "x" and "y" share the same "value" if (x > 1) ... // at this point, the value shared by "x" and "y" is "> 1". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46466 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 13d10f2d8b..1b2545a3fd 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -47,33 +47,61 @@ using llvm::APSInt; /// Stmt*. Use cast<> or dyn_cast<> to get actual pointer type //===----------------------------------------------------------------------===// namespace { + +typedef uintptr_t SymbolID; class VISIBILITY_HIDDEN ValueKey { - uintptr_t Raw; - + uintptr_t Raw; void operator=(const ValueKey& RHS); // Do not implement. + public: - enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, Flags=0x3 }; - inline void* getPtr() const { return reinterpret_cast(Raw & ~Flags); } - inline Kind getKind() const { return (Kind) (Raw & Flags); } + enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, // L-Value Bindings. + IsSymbol=0x3, // Symbol Bindings. + Flags=0x3 }; + + inline Kind getKind() const { + return (Kind) (Raw & Flags); + } + + inline void* getPtr() const { + assert (getKind() != IsSymbol); + return reinterpret_cast(Raw & ~Flags); + } + + inline SymbolID getSymbolID() const { + assert (getKind() == IsSymbol); + return Raw >> 2; + } ValueKey(const ValueDecl* VD) - : Raw(reinterpret_cast(VD) | IsDecl) { assert(VD); } + : Raw(reinterpret_cast(VD) | IsDecl) { + assert(VD && "ValueDecl cannot be NULL."); + } ValueKey(Stmt* S, bool isBlkExpr = false) : Raw(reinterpret_cast(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){ - assert(S); + assert(S && "Tracked statement cannot be NULL."); } + ValueKey(SymbolID V) + : Raw((V << 2) | IsSymbol) {} + + bool isSymbol() const { return getKind() == IsSymbol; } bool isSubExpr() const { return getKind() == IsSubExpr; } - bool isDecl() const { return getKind() == IsDecl; } + bool isDecl() const { return getKind() == IsDecl; } inline void Profile(llvm::FoldingSetNodeID& ID) const { - ID.AddPointer(getPtr()); + ID.AddInteger(isSymbol() ? 1 : 0); + + if (isSymbol()) + ID.AddInteger((uint64_t) getSymbolID()); + else + ID.AddPointer(getPtr()); } inline bool operator==(const ValueKey& X) const { - return getPtr() == X.getPtr(); + return isSymbol() ? getSymbolID() == X.getSymbolID() + : getPtr() == X.getPtr(); } inline bool operator!=(const ValueKey& X) const { @@ -81,18 +109,10 @@ public: } inline bool operator<(const ValueKey& X) const { - Kind k = getKind(), Xk = X.getKind(); + if (isSymbol()) + return X.isSymbol() ? getSymbolID() < X.getSymbolID() : false; - if (k == IsDecl) { - if (Xk != IsDecl) - return false; - } - else { - if (Xk == IsDecl) - return true; - } - - return getPtr() < X.getPtr(); + return getPtr() < X.getPtr(); } }; } // end anonymous namespace @@ -103,7 +123,7 @@ namespace llvm { return V.getKind() == ValueKey::IsDecl; } template<> inline bool isa(const ValueKey& V) { - return ((unsigned) V.getKind()) != ValueKey::IsDecl; + return ((unsigned) V.getKind()) < ValueKey::IsDecl; } template<> struct VISIBILITY_HIDDEN cast_retty_impl { typedef const ValueDecl* ret_type; @@ -129,39 +149,50 @@ typedef llvm::ImmutableSet APSIntSetTy; class VISIBILITY_HIDDEN ValueManager { - APSIntSetTy::Factory APSIntSetFactory; ASTContext* Ctx; + typedef llvm::FoldingSet > APSIntSetTy; + APSIntSetTy APSIntSet; + + llvm::BumpPtrAllocator BPAlloc; + public: ValueManager() {} - ~ValueManager() {} + ~ValueManager(); void setContext(ASTContext* ctx) { Ctx = ctx; } ASTContext* getContext() const { return Ctx; } - APSIntSetTy GetEmptyAPSIntSet() { - return APSIntSetFactory.GetEmptySet(); - } - - APSIntSetTy AddToSet(const APSIntSetTy& Set, const APSInt& Val) { - return APSIntSetFactory.Add(Set, Val); - } + APSInt& getValue(const APSInt& X); + }; } // end anonymous namespace -template