]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix crash in body farm for getter without implicit self.
authorDevin Coughlin <dcoughlin@apple.com>
Wed, 11 Jan 2017 01:02:34 +0000 (01:02 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Wed, 11 Jan 2017 01:02:34 +0000 (01:02 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291635 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BodyFarm.cpp
test/Analysis/properties.m

index d202a0406461ca8003f568f2cdc57fa00ca2815d..56c812c34c507cb85a5dcc43fde8fa9e98e170ee 100644 (file)
@@ -467,6 +467,8 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx,
   ASTMaker M(Ctx);
 
   const VarDecl *selfVar = Prop->getGetterMethodDecl()->getSelfDecl();
+  if (!selfVar)
+    return nullptr;
 
   Expr *loadedIVar =
     M.makeObjCIvarRef(
index b1305341e5d4b9cd232e8efc9f9d8a0299c3042f..235a9687821d57b4f5ef1a0f7194eea3e28190cb 100644 (file)
@@ -315,6 +315,32 @@ void testConsistencyAssign(Person *p) {
 }
 @end
 
+__attribute__((objc_root_class))
+@interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
+@end
+
+@protocol HasStuff
+@property (nonatomic, readonly) int stuffProperty;
+@end
+
+@interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Private)
+@property (nonatomic, readonly) int stuffProperty;
+@end
+
+@interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Internal) <HasStuff>
+@end
+
+@interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory() <HasStuff>
+@end
+
+@implementation ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
+@synthesize stuffProperty = _stuffProperty;
+
+-(void)foo {
+  (void)self.stuffProperty;
+}
+@end
+
 //------
 // Setter ivar invalidation.
 //------