[cfe-commits] r46584 - /cfe/trunk/Analysis/GRConstants.cpp

Ted Kremenek kremenek at apple.com
Wed Jan 30 16:09:57 PST 2008


Author: kremenek
Date: Wed Jan 30 18:09:56 2008
New Revision: 46584

URL: http://llvm.org/viewvc/llvm-project?rev=46584&view=rev
Log:
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.

Modified:
    cfe/trunk/Analysis/GRConstants.cpp

Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46584&r1=46583&r2=46584&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Wed Jan 30 18:09:56 2008
@@ -327,6 +327,8 @@
   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 @@
                             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 @@
   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 @@
 
 namespace {
   
-enum { LValueDeclKind, NumLValueKind };
+enum { SymbolicLValueKind, LValueDeclKind, NumLValueKind };
 
+class VISIBILITY_HIDDEN SymbolicLValue : public LValue {
+public:
+  SymbolicLValue(unsigned SymID)
+   : LValue(SymbolicLValueKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
+  
+  SymbolID getSymbolID() const {
+    return (SymbolID) reinterpret_cast<uintptr_t>(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 @@
                                        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 @@
       break;
 
     case LValueKind:
-      assert (false && "FIXME: LValue printing not implemented.");  
+      cast<LValue>(this)->print(Out);
       break;
       
     case UninitializedKind:
@@ -705,6 +726,22 @@
   }
 }
 
+void LValue::print(std::ostream& Out) const {
+  switch (getSubKind()) {  
+    case SymbolicLValueKind:
+      Out << '$' << cast<SymbolicLValue>(this)->getSymbolID();
+      break;
+      
+    case LValueDeclKind:
+      Out << cast<LValueDecl>(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 @@
     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;
   }





More information about the cfe-commits mailing list