[cfe-commits] r67395 - in /cfe/trunk: include/clang/Analysis/PathSensitive/SVals.h include/clang/Analysis/PathSensitive/SymbolManager.h lib/Analysis/GRExprEngine.cpp lib/Analysis/SVals.cpp lib/Analysis/SymbolManager.cpp

Ted Kremenek kremenek at apple.com
Fri Mar 20 13:10:46 PDT 2009


Author: kremenek
Date: Fri Mar 20 15:10:45 2009
New Revision: 67395

URL: http://llvm.org/viewvc/llvm-project?rev=67395&view=rev
Log:
GRExprEngine:
- Conjure symbols at '--' and '++' unary operations
- Add utility method SVal::GetConjuredSymbolVal() and constify some arguments
  along the way.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
    cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/SVals.cpp
    cfe/trunk/lib/Analysis/SymbolManager.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h?rev=67395&r1=67394&r2=67395&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h Fri Mar 20 15:10:45 2009
@@ -74,6 +74,9 @@
   /// GetRValueSymbolVal - make a unique symbol for value of R.
   static SVal GetRValueSymbolVal(SymbolManager& SymMgr, const MemRegion* R);
 
+  static SVal GetConjuredSymbolVal(SymbolManager& SymMgr, const Expr *E,
+                                   unsigned Count);  
+
   inline bool isUnknown() const {
     return getRawKind() == UnknownKind;
   }

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h?rev=67395&r1=67394&r2=67395&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h Fri Mar 20 15:10:45 2009
@@ -135,25 +135,25 @@
 };
 
 class SymbolConjured : public SymbolData {
-  Stmt* S;
+  const Stmt* S;
   QualType T;
   unsigned Count;
   const void* SymbolTag;
 
 public:
-  SymbolConjured(SymbolRef Sym, Stmt* s, QualType t, unsigned count,
+  SymbolConjured(SymbolRef Sym, const Stmt* s, QualType t, unsigned count,
                  const void* symbolTag)
     : SymbolData(ConjuredKind, Sym), S(s), T(t), Count(count),
       SymbolTag(symbolTag) {}
   
-  Stmt* getStmt() const { return S; }
+  const Stmt* getStmt() const { return S; }
   unsigned getCount() const { return Count; }
   const void* getTag() const { return SymbolTag; }
   
   QualType getType(ASTContext&) const;
   
-  static void Profile(llvm::FoldingSetNodeID& profile, Stmt* S, QualType T,
-                      unsigned Count, const void* SymbolTag) {    
+  static void Profile(llvm::FoldingSetNodeID& profile, const Stmt* S,
+                      QualType T, unsigned Count, const void* SymbolTag) {    
     profile.AddInteger((unsigned) ConjuredKind);
     profile.AddPointer(S);
     profile.Add(T);
@@ -221,10 +221,10 @@
 
   /// Make a unique symbol for MemRegion R according to its kind.
   SymbolRef getRegionRValueSymbol(const MemRegion* R);
-  SymbolRef getConjuredSymbol(Stmt* E, QualType T, unsigned VisitCount,
+  SymbolRef getConjuredSymbol(const Stmt* E, QualType T, unsigned VisitCount,
                               const void* SymbolTag = 0);
 
-  SymbolRef getConjuredSymbol(Expr* E, unsigned VisitCount,
+  SymbolRef getConjuredSymbol(const Expr* E, unsigned VisitCount,
                               const void* SymbolTag = 0) {    
     return getConjuredSymbol(E, E->getType(), VisitCount, SymbolTag);
   }

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=67395&r1=67394&r2=67395&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Fri Mar 20 15:10:45 2009
@@ -2449,7 +2449,13 @@
       BinaryOperator::Opcode Op = U->isIncrementOp() ? BinaryOperator::Add
                                                      : BinaryOperator::Sub;
 
-      SVal Result = EvalBinOp(Op, V2, MakeConstantVal(1U, U));      
+      SVal Result = EvalBinOp(Op, V2, MakeConstantVal(1U, U));    
+      
+      // Conjure a new symbol if necessary to recover precision.
+      if (Result.isUnknown() || !getConstraintManager().canReasonAbout(Result))
+        Result = SVal::GetConjuredSymbolVal(SymMgr, Ex,
+                                            Builder->getCurrentBlockCount());
+      
       state = BindExpr(state, U, U->isPostfix() ? V2 : Result);
 
       // Perform the store.      

Modified: cfe/trunk/lib/Analysis/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=67395&r1=67394&r2=67395&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Fri Mar 20 15:10:45 2009
@@ -338,6 +338,23 @@
   return UnknownVal();
 }
 
+SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, const Expr* E,
+                                unsigned Count) {
+
+  QualType T = E->getType();
+  
+  if (Loc::IsLocType(T)) {
+    SymbolRef Sym = SymMgr.getConjuredSymbol(E, Count);        
+    return loc::SymbolVal(Sym);
+  }
+  else if (T->isIntegerType() && T->isScalarType()) {
+    SymbolRef Sym = SymMgr.getConjuredSymbol(E, Count);        
+    return nonloc::SymbolVal(Sym);                    
+  }
+
+  return UnknownVal();
+}
+
 nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
                                                 unsigned Bits) {
   return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));

Modified: cfe/trunk/lib/Analysis/SymbolManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SymbolManager.cpp?rev=67395&r1=67394&r2=67395&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/SymbolManager.cpp (original)
+++ cfe/trunk/lib/Analysis/SymbolManager.cpp Fri Mar 20 15:10:45 2009
@@ -52,7 +52,8 @@
   return SymbolCounter++;
 }
 
-SymbolRef SymbolManager::getConjuredSymbol(Stmt* E, QualType T, unsigned Count,
+SymbolRef SymbolManager::getConjuredSymbol(const Stmt* E, QualType T,
+                                           unsigned Count,
                                            const void* SymbolTag) {
   
   llvm::FoldingSetNodeID profile;





More information about the cfe-commits mailing list