[analyzer] Fix assertion in ReturnVisitor for body-farm synthesized getters
authorDevin Coughlin <dcoughlin@apple.com>
Tue, 12 Apr 2016 00:53:26 +0000 (00:53 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Tue, 12 Apr 2016 00:53:26 +0000 (00:53 +0000)
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.

llvm-svn: 266031

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/test/Analysis/inlining/false-positive-suppression.m

index e0f0147..657d33f 100644 (file)
@@ -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());
   }
 
index 7be1cb8..d967820 100644 (file)
@@ -45,6 +45,8 @@ __attribute__((objc_root_class))
 
 @property(readonly) int *propertyReturningNull;
 
+@property(readonly) int *synthesizedProperty;
+
 @end
 
 @implementation SomeClass
@@ -72,3 +74,14 @@ void testPropertyReturningNull(SomeClass *sc) {
   // expected-warning@-2 {{Dereference of null pointer}}
 #endif
 }
+
+void testSynthesizedPropertyReturningNull(SomeClass *sc) {
+  if (sc.synthesizedProperty)
+    return;
+
+  int *result = sc.synthesizedProperty;
+  *result = 1;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Dereference of null pointer}}
+#endif
+}