r266031 - [analyzer] Fix assertion in ReturnVisitor for body-farm synthesized getters

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 11 17:53:26 PDT 2016


Author: dcoughlin
Date: Mon Apr 11 19:53:26 2016
New Revision: 266031

URL: http://llvm.org/viewvc/llvm-project?rev=266031&view=rev
Log:
[analyzer] Fix assertion in ReturnVisitor for body-farm synthesized getters
Don't emit a path note marking the return site if the return statement does not
have a valid location. This fixes an assertion failure I introduced in r265839.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
    cfe/trunk/test/Analysis/inlining/false-positive-suppression.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=266031&r1=266030&r2=266031&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr 11 19:53:26 2016
@@ -324,6 +324,9 @@ public:
     }
 
     PathDiagnosticLocation L(Ret, BRC.getSourceManager(), StackFrame);
+    if (!L.isValid() || !L.asLocation().isValid())
+      return nullptr;
+
     return new PathDiagnosticEventPiece(L, Out.str());
   }
 

Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.m?rev=266031&r1=266030&r2=266031&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.m (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.m Mon Apr 11 19:53:26 2016
@@ -45,6 +45,8 @@ __attribute__((objc_root_class))
 
 @property(readonly) int *propertyReturningNull;
 
+ at property(readonly) int *synthesizedProperty;
+
 @end
 
 @implementation SomeClass
@@ -70,5 +72,16 @@ void testPropertyReturningNull(SomeClass
   *result = 1;
 #ifndef SUPPRESSED
   // expected-warning at -2 {{Dereference of null pointer}}
+#endif
+}
+
+void testSynthesizedPropertyReturningNull(SomeClass *sc) {
+  if (sc.synthesizedProperty)
+    return;
+
+  int *result = sc.synthesizedProperty;
+  *result = 1;
+#ifndef SUPPRESSED
+  // expected-warning at -2 {{Dereference of null pointer}}
 #endif
 }




More information about the cfe-commits mailing list