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);
+
+@interface ClassWithProperties: NSObject
+@property(copy, nullable) NSObject *x;
+-(void) method;
+@end;
+@implementation ClassWithProperties
+-(void) method {
+  takesNonnull(self.x); // expected-warning{{Nullable pointer is passed to a 
callee that requires a non-null 1st parameter}}
+}
+@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) {


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);
+
+@interface ClassWithProperties: NSObject
+@property(copy, nullable) NSObject *x;
+-(void) method;
+@end;
+@implementation ClassWithProperties
+-(void) method {
+  takesNonnull(self.x); // expected-warning{{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
+}
+@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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to