]> granicus.if.org Git - clang/commitdiff
If a nonnull argument evaluates to UnknownVal, don't warn (and don't crash).
authorJordy Rose <jediknil@belkadan.com>
Mon, 21 Jun 2010 20:08:28 +0000 (20:08 +0000)
committerJordy Rose <jediknil@belkadan.com>
Mon, 21 Jun 2010 20:08:28 +0000 (20:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106456 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/AttrNonNullChecker.cpp
test/Analysis/null-deref-ps.c

index 471cf19717038d4798b09192af97a128a1219f38..d0bccb27b4059fbad23a46acc59766bd549b75a4 100644 (file)
@@ -60,11 +60,16 @@ void AttrNonNullChecker::PreVisitCallExpr(CheckerContext &C,
     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
index 5a1049c7d71ec24ec91a2cd23ad289d0adbca1ac..eac7957fb9219b90cffa119b301895bf86b88cd2 100644 (file)
@@ -118,6 +118,11 @@ void f6d(int *p) {
   }  
 }
 
+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) {