[cfe-commits] r106456 - in /cfe/trunk: lib/Checker/AttrNonNullChecker.cpp test/Analysis/null-deref-ps.c

Jordy Rose jediknil at belkadan.com
Mon Jun 21 13:08:28 PDT 2010


Author: jrose
Date: Mon Jun 21 15:08:28 2010
New Revision: 106456

URL: http://llvm.org/viewvc/llvm-project?rev=106456&view=rev
Log:
If a nonnull argument evaluates to UnknownVal, don't warn (and don't crash).

Modified:
    cfe/trunk/lib/Checker/AttrNonNullChecker.cpp
    cfe/trunk/test/Analysis/null-deref-ps.c

Modified: cfe/trunk/lib/Checker/AttrNonNullChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/AttrNonNullChecker.cpp?rev=106456&r1=106455&r2=106456&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/AttrNonNullChecker.cpp (original)
+++ cfe/trunk/lib/Checker/AttrNonNullChecker.cpp Mon Jun 21 15:08:28 2010
@@ -60,11 +60,16 @@
     if (!Att->isNonNull(idx))
       continue;
 
-    const DefinedSVal &V = cast<DefinedSVal>(state->getSVal(*I));
+    SVal V = state->getSVal(*I);
+    DefinedSVal *DV = dyn_cast<DefinedSVal>(&V);
+
+    // If the value is unknown or undefined, we can't perform this check.
+    if (!DV)
+      continue;
 
     ConstraintManager &CM = C.getConstraintManager();
     const GRState *stateNotNull, *stateNull;
-    llvm::tie(stateNotNull, stateNull) = CM.AssumeDual(state, V);
+    llvm::tie(stateNotNull, stateNull) = CM.AssumeDual(state, *DV);
 
     if (stateNull && !stateNotNull) {
       // Generate an error node.  Check for a null node in case

Modified: cfe/trunk/test/Analysis/null-deref-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps.c?rev=106456&r1=106455&r2=106456&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Mon Jun 21 15:08:28 2010
@@ -118,6 +118,11 @@
   }  
 }
 
+void f6e(int *p, int offset) {
+  // PR7406 - crash from treating an UnknownVal as defined, to see if it's 0.
+  bar((p+offset)+1, 0); // not crash
+}
+
 int* qux();
 
 int f7(int x) {





More information about the cfe-commits mailing list