r351609 - [analyzer] Do not try to body-farm Objective-C properties with custom accessors.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 18 14:52:13 PST 2019


Author: dergachev
Date: Fri Jan 18 14:52:13 2019
New Revision: 351609

URL: http://llvm.org/viewvc/llvm-project?rev=351609&view=rev
Log:
[analyzer] Do not try to body-farm Objective-C properties with custom accessors.

If a property is defined with a custom getter, we should not behave as if
the getter simply returns an instance variable. We don't support setters,
so they aren't affected.

On top of being the right thing to do, this also fixes a crash on
the newly added test - in which a property and its getter are defined
in two separate categories.

rdar://problem/47051544

Differential Revision: https://reviews.llvm.org/D56823

Modified:
    cfe/trunk/lib/Analysis/BodyFarm.cpp
    cfe/trunk/test/Analysis/properties.m

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=351609&r1=351608&r2=351609&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Fri Jan 18 14:52:13 2019
@@ -807,6 +807,11 @@ Stmt *BodyFarm::getBody(const ObjCMethod
 
   D = D->getCanonicalDecl();
 
+  // We should not try to synthesize explicitly redefined accessors.
+  // We do not know for sure how they behave.
+  if (!D->isImplicit())
+    return nullptr;
+
   Optional<Stmt *> &Val = Bodies[D];
   if (Val.hasValue())
     return Val.getValue();

Modified: cfe/trunk/test/Analysis/properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/properties.m?rev=351609&r1=351608&r2=351609&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/properties.m (original)
+++ cfe/trunk/test/Analysis/properties.m Fri Jan 18 14:52:13 2019
@@ -1005,3 +1005,38 @@ void testNoCrashWhenAccessPropertyAndThe
 
 #endif // non-ARC
 
+ at interface ExplicitAccessorInCategory : NSObject
+ at property(readonly) int normal;
+- (int)normal;
+ at property(readonly) int no_custom_accessor;
+ at end
+
+ at interface ExplicitAccessorInCategory ()
+ at property(readonly) int in_category;
+
+ at property(readonly) int still_no_custom_accessor;
+// This is an ordinary method, not a getter.
+- (int)still_no_custom_accessor;
+ at end
+
+ at interface ExplicitAccessorInCategory ()
+- (int)in_category;
+
+// This is an ordinary method, not a getter.
+- (int)no_custom_accessor;
+ at end
+
+ at implementation ExplicitAccessorInCategory
+- (void)foo {
+	// Make sure we don't farm bodies for explicit accessors: in particular,
+	// we're not sure that the accessor always returns the same value.
+	clang_analyzer_eval(self.normal == self.normal); // expected-warning{{UNKNOWN}}
+	// Also this used to crash.
+	clang_analyzer_eval(self.in_category == self.in_category); // expected-warning{{UNKNOWN}}
+
+	// When there is no explicit accessor defined (even if it looks like there is),
+	// farm the getter body and see if it does actually always yield the same value.
+	clang_analyzer_eval(self.no_custom_accessor == self.no_custom_accessor); // expected-warning{{TRUE}}
+	clang_analyzer_eval(self.still_no_custom_accessor == self.still_no_custom_accessor); // expected-warning{{TRUE}}
+}
+ at end




More information about the cfe-commits mailing list