From b8c84807241470d56e19d87e5875c7c66c67a865 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Mon, 22 Aug 2016 21:50:22 +0000 Subject: [PATCH] [SemaObjC] Do not RebuildObjCMessageExpr without valid method decl Fix crash-on-invalid in ObjC Sema by avoiding to rebuild a message expression to a 'super' class in case the method to call does not exist (i.e. comes from another missing identifier). In this case, the typo transform is invoked upon the message expression in an attempt to solve a typo in a 'super' call parameters, but it crashes since it assumes the method to call has a valid declaration. rdar://problem/27305403 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279481 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/TreeTransform.h | 3 +++ test/SemaObjC/call-super-2.m | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 8ea0b015e5..c53505d10a 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -11174,6 +11174,9 @@ TreeTransform::TransformObjCMessageExpr(ObjCMessageExpr *E) { } else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { + if (!E->getMethodDecl()) + return ExprError(); + // Build a new class message send to 'super'. SmallVector SelLocs; E->getSelectorLocs(SelLocs); diff --git a/test/SemaObjC/call-super-2.m b/test/SemaObjC/call-super-2.m index 8927f3b528..01acff70c2 100644 --- a/test/SemaObjC/call-super-2.m +++ b/test/SemaObjC/call-super-2.m @@ -106,3 +106,18 @@ id objc_getClass(const char *s); } @end +@class C; +@interface A // expected-note {{receiver is instance of class declared here}} +- (instancetype)initWithCoder:(A *)coder; +@end + +@interface B : A +@end + +@implementation B +- (instancetype)initWithCoder:(C *)coder { + if (0 != (self = [super initWithCode:code])) // expected-error {{use of undeclared identifier 'code'}} expected-warning {{instance method '-initWithCode:' not found}} + return (void *)0; + return (void *)0; +} +@end -- 2.50.1