[cfe-commits] r89526 - /cfe/trunk/lib/Analysis/DereferenceChecker.cpp

Ted Kremenek kremenek at apple.com
Fri Nov 20 17:50:48 PST 2009


Author: kremenek
Date: Fri Nov 20 19:50:48 2009
New Revision: 89526

URL: http://llvm.org/viewvc/llvm-project?rev=89526&view=rev
Log:
Restructure DereferenceChecker slightly to handle caching out when we would report a null dereference more than once.

Modified:
    cfe/trunk/lib/Analysis/DereferenceChecker.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/DereferenceChecker.cpp (original)
+++ cfe/trunk/lib/Analysis/DereferenceChecker.cpp Fri Nov 20 19:50:48 2009
@@ -82,29 +82,32 @@
   
   // The explicit NULL case.
   if (nullState) {
-    // Generate an error node.
-    ExplodedNode *N = C.GenerateNode(S, nullState, true);    
-    if (N) {      
-      if (!notNullState) {
-        // We know that 'location' cannot be non-null.  This is what
-        // we call an "explicit" null dereference.        
-        if (!BT_null)
-          BT_null = new BuiltinBug("Null pointer dereference",
-                                   "Dereference of null pointer");
-
-        EnhancedBugReport *report =
-          new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
-        report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
-                                  bugreporter::GetDerefExpr(N));
-        
-        C.EmitReport(report);
+    if (!notNullState) {    
+      // Generate an error node.
+      ExplodedNode *N = C.GenerateNode(S, nullState, true);
+      if (!N)
         return;
-      }
+      
+      // We know that 'location' cannot be non-null.  This is what
+      // we call an "explicit" null dereference.        
+      if (!BT_null)
+        BT_null = new BuiltinBug("Null pointer dereference",
+                                 "Dereference of null pointer");
 
+      EnhancedBugReport *report =
+        new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
+      report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
+                                bugreporter::GetDerefExpr(N));
+      
+      C.EmitReport(report);
+      return;
+    }
+    else {
       // Otherwise, we have the case where the location could either be
       // null or not-null.  Record the error node as an "implicit" null
-      // dereference.
-      ImplicitNullDerefNodes.push_back(N);
+      // dereference.      
+      if (ExplodedNode *N = C.GenerateNode(S, nullState, true))
+        ImplicitNullDerefNodes.push_back(N);
     }
   }
   





More information about the cfe-commits mailing list