[cfe-commits] r47964 - in /cfe/trunk: Analysis/GRExprEngine.cpp include/clang/Analysis/PathSensitive/ExplodedGraph.h include/clang/Analysis/PathSensitive/GRCoreEngine.h

Ted Kremenek kremenek at apple.com
Wed Mar 5 13:15:02 PST 2008


Author: kremenek
Date: Wed Mar  5 15:15:02 2008
New Revision: 47964

URL: http://llvm.org/viewvc/llvm-project?rev=47964&view=rev
Log:
Fixed bug that could case unwanted bifurcation of states when evaluating calls.

Modified:
    cfe/trunk/Analysis/GRExprEngine.cpp
    cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h

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

==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Wed Mar  5 15:15:02 2008
@@ -21,6 +21,18 @@
 #include <sstream>
 #endif
 
+// SaveAndRestore - A utility class that uses RIIA to save and restore
+//  the value of a variable.
+template<typename T>
+struct VISIBILITY_HIDDEN SaveAndRestore {
+  SaveAndRestore(T& x) : X(x), old_value(x) {}
+  ~SaveAndRestore() { X = old_value; }
+  T get() { return old_value; }
+  
+  T& X;
+  T old_value;
+};
+
 using namespace clang;
 using llvm::dyn_cast;
 using llvm::cast;
@@ -482,7 +494,27 @@
       }
       
       continue;
-    }  
+    }
+    
+    // Check for the "noreturn" attribute.
+    
+    SaveAndRestore<bool> OldSink(Builder->BuildSinks);
+    
+    if (isa<lval::FuncVal>(L))
+      if (cast<lval::FuncVal>(L).getDecl()->getAttr<NoReturnAttr>()) {
+        for (NodeSet::iterator I=Dst.begin(), E=Dst.end(); I != E; ++I ) {
+          
+          NodeTy* N = *I;
+          
+          if (!N->isSink())
+            N->markAsSink();
+        }
+        
+        Builder->BuildSinks = true;
+      }
+    
+    // Evaluate the call.
+    
     
     bool invalidateArgs = false;
     
@@ -506,7 +538,9 @@
 
         if (isa<LVal>(V))
           St = SetRVal(St, cast<LVal>(V), UnknownVal());
-      }      
+      }
+      
+      Nodify(Dst, CE, *DI, St);
     }
     else {
 
@@ -542,23 +576,6 @@
       if (Dst.size() == size)
         Nodify(Dst, CE, *DI, St);
     }
-    
-    // Check for the "noreturn" attribute.
-    
-    if (isa<lval::FuncVal>(L))
-      if (cast<lval::FuncVal>(L).getDecl()->getAttr<NoReturnAttr>()) {
-        
-        NodeTy* N = Builder->generateNode(CE, St, *DI);
-          
-        if (N) {
-          N->markAsSink();
-          NoReturnCalls.insert(N);
-        }
-        
-        continue;
-      }
-    
-    Nodify(Dst, CE, *DI, St);
   }
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h Wed Mar  5 15:15:02 2008
@@ -389,6 +389,8 @@
 
   inline unsigned size() const { return Impl.size();  }
   inline bool empty()    const { return Impl.empty(); }
+
+  inline void clear() { Impl.clear(); }
   
   inline iterator begin() { return Impl.begin(); }
   inline iterator end()   { return Impl.end();   }

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Wed Mar  5 15:15:02 2008
@@ -162,7 +162,7 @@
   GRStmtNodeBuilderImpl& NB;
   
 public:
-  GRStmtNodeBuilder(GRStmtNodeBuilderImpl& nb) : NB(nb) {}
+  GRStmtNodeBuilder(GRStmtNodeBuilderImpl& nb) : NB(nb), BuildSinks(false) {}
     
   NodeTy* getLastNode() const {
     return static_cast<NodeTy*>(NB.getLastNode());
@@ -186,10 +186,16 @@
     }
     
     NodeTy* N = generateNode(S, St, Pred);
-    Dst.Add(N);
+    
+    if (N && BuildSinks)
+      N->markAsSink();
+    else
+      Dst.Add(N);
+    
     return N;
   }
   
+  bool BuildSinks;  
 };
   
 class GRBranchNodeBuilderImpl {





More information about the cfe-commits mailing list