r178933 - [analyzer] Fix null tracking for the given test case, by using the proper state and removing redundant code.

Anna Zaks ganna at apple.com
Fri Apr 5 16:50:11 PDT 2013


Author: zaks
Date: Fri Apr  5 18:50:11 2013
New Revision: 178933

URL: http://llvm.org/viewvc/llvm-project?rev=178933&view=rev
Log:
[analyzer] Fix null tracking for the given test case, by using the proper state and removing redundant code.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=178933&r1=178932&r2=178933&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Apr  5 18:50:11 2013
@@ -926,22 +926,7 @@ bool bugreporter::trackNullOrUndefValue(
 
     if (R) {
       // Mark both the variable region and its contents as interesting.
-      SVal V = state->getRawSVal(loc::MemRegionVal(R));
-
-      // If the value matches the default for the variable region, that
-      // might mean that it's been cleared out of the state. Fall back to
-      // the full argument expression (with casts and such intact).
-      if (IsArg) {
-        bool UseArgValue = V.isUnknownOrUndef() || V.isZeroConstant();
-        if (!UseArgValue) {
-          const SymbolRegionValue *SRV =
-            dyn_cast_or_null<SymbolRegionValue>(V.getAsLocSymbol());
-          if (SRV)
-            UseArgValue = (SRV->getRegion() == R);
-        }
-        if (UseArgValue)
-          V = state->getSValAsScalarOrLoc(S, N->getLocationContext());
-      }
+      SVal V = LVState->getRawSVal(loc::MemRegionVal(R));
 
       report.markInteresting(R);
       report.markInteresting(V);
@@ -960,11 +945,11 @@ bool bugreporter::trackNullOrUndefValue(
         report.addVisitor(ConstraintTracker);
 
         // Add visitor, which will suppress inline defensive checks.
-        if (N->getState()->isNull(V).isConstrainedTrue() &&
+        if (LVState->isNull(V).isConstrainedTrue() &&
             EnableNullFPSuppression) {
           BugReporterVisitor *IDCSuppressor =
             new SuppressInlineDefensiveChecksVisitor(V.castAs<DefinedSVal>(),
-                                                     N);
+                                                     LVNode);
           report.addVisitor(IDCSuppressor);
         }
       }

Modified: cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp?rev=178933&r1=178932&r2=178933&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp (original)
+++ cfe/trunk/test/Analysis/inlining/inline-defensive-checks.cpp Fri Apr  5 18:50:11 2013
@@ -52,4 +52,22 @@ void radar13224271_caller()
 	Ty value;
 	radar13224271_callee(getTyVal(), value );
 	notNullArg(value); // no-warning
+}
+
+struct Foo {
+	int *ptr;
+	Foo(int *p)  {
+		*p = 1; // no-warning
+	}
+};
+void idc(int *p3) {
+  if (p3)
+    ;
+}
+int *retNull() {
+  return 0;
+}
+void test(int *p1, int *p2) {
+  idc(p1);
+	Foo f(p1);
 }
\ No newline at end of file





More information about the cfe-commits mailing list