r291635 - [analyzer] Fix crash in body farm for getter without implicit self.

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 17:02:34 PST 2017


Author: dcoughlin
Date: Tue Jan 10 19:02:34 2017
New Revision: 291635

URL: http://llvm.org/viewvc/llvm-project?rev=291635&view=rev
Log:
[analyzer] Fix crash in body farm for getter without implicit self.

Fix a crash in body farm when synthesizing a getter for a property
synthesized for a property declared in a protocol on a class extension
that shadows a declaration of the property in a category.

In this case, Sema doesn't fill in the implicit 'self' parameter for the getter
in the category, which leads to a crash when trying to synthesize the getter
for it.

To avoid the crash, skip getter synthesis in body farm if the self parameter is
not filled int.

rdar://problem/29938138

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=291635&r1=291634&r2=291635&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue Jan 10 19:02:34 2017
@@ -467,6 +467,8 @@ static Stmt *createObjCPropertyGetter(AS
   ASTMaker M(Ctx);
 
   const VarDecl *selfVar = Prop->getGetterMethodDecl()->getSelfDecl();
+  if (!selfVar)
+    return nullptr;
 
   Expr *loadedIVar =
     M.makeObjCIvarRef(

Modified: cfe/trunk/test/Analysis/properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/properties.m?rev=291635&r1=291634&r2=291635&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/properties.m (original)
+++ cfe/trunk/test/Analysis/properties.m Tue Jan 10 19:02:34 2017
@@ -315,6 +315,32 @@ void testConsistencyAssign(Person *p) {
 }
 @end
 
+__attribute__((objc_root_class))
+ at interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
+ at end
+
+ at protocol HasStuff
+ at property (nonatomic, readonly) int stuffProperty;
+ at end
+
+ at interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Private)
+ at property (nonatomic, readonly) int stuffProperty;
+ at end
+
+ at interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Internal) <HasStuff>
+ at end
+
+ at interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory() <HasStuff>
+ at end
+
+ at implementation ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
+ at synthesize stuffProperty = _stuffProperty;
+
+-(void)foo {
+  (void)self.stuffProperty;
+}
+ at end
+
 //------
 // Setter ivar invalidation.
 //------




More information about the cfe-commits mailing list