[PATCH] D32437: [analyzer] Nullability: fix a crash when adding notes inside a synthesized property accessor.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 08:45:40 PDT 2017


NoQ created this revision.

In this test case, the body of a property is autosynthesized, and its source locations are invalid. Path diagnostic locations must refer to valid source locations, hence we're hitting an assertion. This patch disables the bugvisitor's note, however we'd need to figure out where to stick it eventually. These new "extra notes" of mine might be useful (we could put them at property declaration), i could add them if everybody likes this idea.


https://reviews.llvm.org/D32437

Files:
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  test/Analysis/nullability.mm


Index: test/Analysis/nullability.mm
===================================================================
--- test/Analysis/nullability.mm
+++ test/Analysis/nullability.mm
@@ -525,3 +525,15 @@
   return nil; // no-warning
 }
 @end
+
+void takesNonnull(NSObject *_Nonnull y);
+
+ at interface ClassWithProperties: NSObject
+ at property(copy, nullable) NSObject *x;
+-(void) method;
+ at end;
+ at implementation ClassWithProperties
+-(void) method {
+  takesNonnull(self.x); // expected-warning{{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
+}
+ at end
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -324,6 +324,10 @@
       TrackedNullabPrev->getValue() == TrackedNullab->getValue())
     return nullptr;
 
+  if (N->getLocationContext()->getAnalysisDeclContext()
+                             ->isBodyAutosynthesized())
+    return nullptr;
+
   // Retrieve the associated statement.
   const Stmt *S = TrackedNullab->getNullabilitySource();
   if (!S) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32437.96403.patch
Type: text/x-patch
Size: 1167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170424/918540ac/attachment-0001.bin>


More information about the cfe-commits mailing list