From: Ted Kremenek Date: Thu, 31 Jan 2008 00:09:56 +0000 (+0000) Subject: Added 'SymbolicLValue' class to represent LValues whose value is symbolic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4150abf22e31028f89f690812300a2b4ee4b7874;p=clang Added 'SymbolicLValue' class to represent LValues whose value is symbolic. Improved pretty-printing of LValues. Parameters whose values are pointers/references are now assigned SymbolicLValues. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46584 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 36ad5fe20a..b7d068a118 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -327,6 +327,8 @@ public: bool operator==(const RValue& RHS) const { return getRawKind() == RHS.getRawKind() && Data == RHS.Data; } + + static RValue GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl *D); inline bool isValid() const { return getRawKind() != InvalidKind; } inline bool isInvalid() const { return getRawKind() == InvalidKind; } @@ -380,7 +382,6 @@ public: SourceLocation Loc = SourceLocation()); static NonLValue GetValue(ValueManager& ValMgr, IntegerLiteral* I); - static NonLValue GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl *D); static inline NonLValue GetIntTruthValue(ValueManager& ValMgr, bool X) { return GetValue(ValMgr, X ? 1U : 0U, ValMgr.getContext().IntTy); @@ -397,6 +398,7 @@ protected: LValue(unsigned SubKind, void* D) : RValue(D, true, SubKind) {} public: + void print(std::ostream& Out) const; // Equality operators. NonLValue EQ(ValueManager& ValMgr, const LValue& RHS) const; @@ -416,8 +418,22 @@ public: namespace { -enum { LValueDeclKind, NumLValueKind }; +enum { SymbolicLValueKind, LValueDeclKind, NumLValueKind }; +class VISIBILITY_HIDDEN SymbolicLValue : public LValue { +public: + SymbolicLValue(unsigned SymID) + : LValue(SymbolicLValueKind, reinterpret_cast((uintptr_t) SymID)) {} + + SymbolID getSymbolID() const { + return (SymbolID) reinterpret_cast(getRawPtr()); + } + + static inline bool classof(const RValue* V) { + return V->getSubKind() == SymbolicLValueKind; + } +}; + class VISIBILITY_HIDDEN LValueDecl : public LValue { public: LValueDecl(const ValueDecl* vd) @@ -658,8 +674,13 @@ NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) { I->getType()->isUnsignedIntegerType()))); } -NonLValue NonLValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) { - return SymbolicNonLValue(SymMgr.getSymbol(D)); +RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) { + QualType T = D->getType(); + + if (T->isPointerType() || T->isReferenceType()) + return SymbolicLValue(SymMgr.getSymbol(D)); + else + return SymbolicNonLValue(SymMgr.getSymbol(D)); } //===----------------------------------------------------------------------===// @@ -677,7 +698,7 @@ void RValue::print(std::ostream& Out) const { break; case LValueKind: - assert (false && "FIXME: LValue printing not implemented."); + cast(this)->print(Out); break; case UninitializedKind: @@ -705,6 +726,22 @@ void NonLValue::print(std::ostream& Out) const { } } +void LValue::print(std::ostream& Out) const { + switch (getSubKind()) { + case SymbolicLValueKind: + Out << '$' << cast(this)->getSymbolID(); + break; + + case LValueDeclKind: + Out << cast(this)->getDecl()->getIdentifier(); + break; + + default: + assert (false && "Pretty-printed not implemented for this LValue."); + break; + } +} + //===----------------------------------------------------------------------===// // ValueMapTy - A ImmutableMap type Stmt*/Decl*/Symbols to RValues. //===----------------------------------------------------------------------===// @@ -829,16 +866,8 @@ public: FunctionDecl& F = G.getFunctionDecl(); for (FunctionDecl::param_iterator I=F.param_begin(), E=F.param_end(); - I!=E; ++I) { - - // For now we only support symbolic values for non-pointer types. - if ((*I)->getType()->isPointerType() || - (*I)->getType()->isReferenceType()) - continue; - - // FIXME: Set these values to a symbol, not Uninitialized. - St = SetValue(St, LValueDecl(*I), NonLValue::GetSymbolValue(SymMgr, *I)); - } + I!=E; ++I) + St = SetValue(St, LValueDecl(*I), RValue::GetSymbolValue(SymMgr, *I)); return St; }