[cfe-commits] r58138 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/PathSensitive/Store.h lib/Analysis/BasicStore.cpp lib/Analysis/Environment.cpp lib/Analysis/GRExprEngine.cpp lib/Analysis/RegionStore.cpp

Zhongxing Xu xuzhongxing at gmail.com
Sat Oct 25 07:18:57 PDT 2008


Author: zhongxingxu
Date: Sat Oct 25 09:18:57 2008
New Revision: 58138

URL: http://llvm.org/viewvc/llvm-project?rev=58138&view=rev
Log:
Add code for get the lvalue for string literals. Now we return a StringRegion
for StringLiteral lvalue evaluation, instead of directly returning a
loc::StringLiteralVal by the Environment.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
    cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
    cfe/trunk/lib/Analysis/BasicStore.cpp
    cfe/trunk/lib/Analysis/Environment.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/RegionStore.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Sat Oct 25 09:18:57 2008
@@ -355,6 +355,11 @@
   SVal GetLValue(const GRState* St, const VarDecl* D) {
     return StoreMgr->getLValueVar(St, D);
   }
+
+  // Get the lvalue for a StringLiteral.
+  SVal GetLValue(const GRState* St, const StringLiteral* E) {
+    return StoreMgr->getLValueString(St, E);
+  }
   
   // Get the lvalue for an ivar reference.
   SVal GetLValue(const GRState* St, const ObjCIvarDecl* D, SVal Base) {

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Sat Oct 25 09:18:57 2008
@@ -50,7 +50,9 @@
   virtual Store getInitialStore() = 0;
   virtual MemRegionManager& getRegionManager() = 0;
 
-  virtual SVal getLValueVar(const GRState* St, const VarDecl* VD) = 0;  
+  virtual SVal getLValueVar(const GRState* St, const VarDecl* VD) = 0;
+
+  virtual SVal getLValueString(const GRState* St, const StringLiteral* S) = 0;
   
   virtual SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
                              SVal Base) = 0;

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

==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Sat Oct 25 09:18:57 2008
@@ -47,6 +47,7 @@
   }
   
   SVal getLValueVar(const GRState* St, const VarDecl* VD);
+  SVal getLValueString(const GRState* St, const StringLiteral* S);
   SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
   SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D);  
   SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
@@ -88,6 +89,11 @@
 SVal BasicStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
   return loc::MemRegionVal(MRMgr.getVarRegion(VD));
 }
+
+SVal BasicStoreManager::getLValueString(const GRState* St, 
+                                        const StringLiteral* S) {
+  return loc::MemRegionVal(MRMgr.getStringRegion(S));
+}
   
 SVal BasicStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
                                       SVal Base) {

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

==============================================================================
--- cfe/trunk/lib/Analysis/Environment.cpp (original)
+++ cfe/trunk/lib/Analysis/Environment.cpp Sat Oct 25 09:18:57 2008
@@ -42,13 +42,10 @@
         return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
       }
         
-      case Stmt::StringLiteralClass:
-        return Loc::MakeVal(cast<StringLiteral>(E));
-        
-        // Casts where the source and target type are the same
-        // are no-ops.  We blast through these to get the descendant
-        // subexpression that has a value.
-        
+      // Casts where the source and target type are the same
+      // are no-ops.  We blast through these to get the descendant
+      // subexpression that has a value.
+       
       case Stmt::ImplicitCastExprClass:
       case Stmt::ExplicitCastExprClass: {
         CastExpr* C = cast<CastExpr>(E);

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Sat Oct 25 09:18:57 2008
@@ -444,6 +444,13 @@
       //  have "locations" in the sense that we can take their address.
       Dst.Add(Pred);
       return;
+
+    case Stmt::StringLiteralClass: {
+      const GRState* St = GetState(Pred);
+      SVal V = StateMgr.GetLValue(St, cast<StringLiteral>(Ex));
+      MakeNode(Dst, Ex, Pred, SetSVal(St, Ex, V));
+      return;
+    }
       
     default:
       // Arbitrary subexpressions can return aggregate temporaries that

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

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Sat Oct 25 09:18:57 2008
@@ -46,6 +46,8 @@
     return Retrieve(St, loc::MemRegionVal(R));
   }
 
+  SVal getLValueString(const GRState* St, const StringLiteral* S);
+
   SVal getLValueVar(const GRState* St, const VarDecl* VD);
   
   SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
@@ -110,6 +112,11 @@
   return new RegionStoreManager(StMgr);
 }
 
+SVal RegionStoreManager::getLValueString(const GRState* St, 
+                                         const StringLiteral* S) {
+  return loc::MemRegionVal(MRMgr.getStringRegion(S));
+}
+
 SVal RegionStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
   return loc::MemRegionVal(MRMgr.getVarRegion(VD));
 }
@@ -188,6 +195,15 @@
 
 SVal RegionStoreManager::ArrayToPointer(SVal Array) {
   const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion();
+  BasicValueFactory& BasicVals = StateMgr.getBasicVals();
+
+  if (const StringRegion* StringR = dyn_cast<StringRegion>(ArrayR)) {
+    // FIXME: Find a better way to get bit width.
+    nonloc::ConcreteInt Idx(BasicVals.getValue(0, 32, false));
+    ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
+    
+    return loc::MemRegionVal(ER);                    
+  }
 
   const Decl* D = cast<DeclRegion>(ArrayR)->getDecl();
 
@@ -201,12 +217,9 @@
 
   if (const ConstantArrayType* CAT = 
       dyn_cast<ConstantArrayType>(ArrayTy.getTypePtr())) {
-
-    BasicValueFactory& BasicVals = StateMgr.getBasicVals();
     
     nonloc::ConcreteInt Idx(BasicVals.getValue(0, CAT->getSize().getBitWidth(),
                                                false));
-
     ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
     
     return loc::MemRegionVal(ER);





More information about the cfe-commits mailing list