From f3d5db650c525ba2237d1a6bdaa4c698b853bbbd Mon Sep 17 00:00:00 2001 From: Devin Coughlin Date: Tue, 12 Apr 2016 00:53:26 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266031 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 3 +++ test/Analysis/inlining/false-positive-suppression.m | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index e0f014714f..657d33fa7a 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -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()); } diff --git a/test/Analysis/inlining/false-positive-suppression.m b/test/Analysis/inlining/false-positive-suppression.m index 7be1cb8472..d9678206c7 100644 --- a/test/Analysis/inlining/false-positive-suppression.m +++ b/test/Analysis/inlining/false-positive-suppression.m @@ -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 +} -- 2.40.0