[cfe-commits] r73756 - in /cfe/trunk: include/clang/Analysis/PathSensitive/SymbolManager.h lib/Analysis/SVals.cpp lib/Analysis/SymbolManager.cpp test/Analysis/casts.c

Zhongxing Xu xuzhongxing at gmail.com
Thu Jun 18 23:00:32 PDT 2009


Author: zhongxingxu
Date: Fri Jun 19 01:00:32 2009
New Revision: 73756

URL: http://llvm.org/viewvc/llvm-project?rev=73756&view=rev
Log:
A further step of r73690: associate the cast-to type with the created symbol,
because the type of the symbol is used to create the default range. We need the
sign to be consistent.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h
    cfe/trunk/lib/Analysis/SVals.cpp
    cfe/trunk/lib/Analysis/SymbolManager.cpp
    cfe/trunk/test/Analysis/casts.c

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=73756&r1=73755&r2=73756&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SymbolManager.h Fri Jun 19 01:00:32 2009
@@ -83,19 +83,25 @@
   
 class SymbolRegionValue : public SymbolData {
   const MemRegion *R;
+  // We may cast the region to another type, so the expected type of the symbol
+  // may be different from the region's original type.
+  QualType T;
+
 public:
-  SymbolRegionValue(SymbolID sym, const MemRegion *r)
-    : SymbolData(RegionValueKind, sym), R(r) {}
+  SymbolRegionValue(SymbolID sym, const MemRegion *r, QualType t = QualType())
+    : SymbolData(RegionValueKind, sym), R(r), T(t) {}
   
   const MemRegion* getRegion() const { return R; }
 
-  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R) {
+  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion* R,
+		      QualType T) {
     profile.AddInteger((unsigned) RegionValueKind);
     profile.AddPointer(R);
+    T.Profile(profile);
   }
   
   virtual void Profile(llvm::FoldingSetNodeID& profile) {
-    Profile(profile, R);
+    Profile(profile, R, T);
   }
   
   QualType getType(ASTContext&) const;
@@ -240,7 +246,8 @@
   static bool canSymbolicate(QualType T);
 
   /// Make a unique symbol for MemRegion R according to its kind.
-  const SymbolRegionValue* getRegionValueSymbol(const MemRegion* R);
+  const SymbolRegionValue* getRegionValueSymbol(const MemRegion* R, 
+						QualType T = QualType());
   const SymbolConjured* getConjuredSymbol(const Stmt* E, QualType T,
                                           unsigned VisitCount,
                                           const void* SymbolTag = 0);

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

==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Fri Jun 19 01:00:32 2009
@@ -323,10 +323,10 @@
 }
 
 SVal ValueManager::getRegionValueSymbolVal(const MemRegion* R, QualType T) {
-  SymbolRef sym = SymMgr.getRegionValueSymbol(R);
+  SymbolRef sym = SymMgr.getRegionValueSymbol(R, T);
                                 
   if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
-    if (!T.getTypePtr())
+    if (T.isNull())
       T = TR->getValueType(SymMgr.getContext());
 
     // If T is of function pointer type, create a CodeTextRegion wrapping a

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

==============================================================================
--- cfe/trunk/lib/Analysis/SymbolManager.cpp (original)
+++ cfe/trunk/lib/Analysis/SymbolManager.cpp Fri Jun 19 01:00:32 2009
@@ -92,14 +92,14 @@
 }
 
 const SymbolRegionValue* 
-SymbolManager::getRegionValueSymbol(const MemRegion* R) {
+SymbolManager::getRegionValueSymbol(const MemRegion* R, QualType T) {
   llvm::FoldingSetNodeID profile;
-  SymbolRegionValue::Profile(profile, R);
+  SymbolRegionValue::Profile(profile, R, T);
   void* InsertPos;  
   SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);    
   if (!SD) {  
     SD = (SymExpr*) BPAlloc.Allocate<SymbolRegionValue>();
-    new (SD) SymbolRegionValue(SymbolCounter, R);  
+    new (SD) SymbolRegionValue(SymbolCounter, R, T);  
     DataSet.InsertNode(SD, InsertPos);
     ++SymbolCounter;
   }
@@ -166,6 +166,9 @@
 }
 
 QualType SymbolRegionValue::getType(ASTContext& C) const {
+  if (!T.isNull())
+    return T;
+
   if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
     return TR->getValueType(C);
   

Modified: cfe/trunk/test/Analysis/casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/casts.c?rev=73756&r1=73755&r2=73756&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/casts.c (original)
+++ cfe/trunk/test/Analysis/casts.c Fri Jun 19 01:00:32 2009
@@ -25,6 +25,8 @@
   pval = &(t->value);
   tbool = (int *)pval; // Should record the cast-to type here.
   char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
+  if (*tbool == -1)
+    3;
 }
 
 void f2(const char *str) {





More information about the cfe-commits mailing list