[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

llvm-svn: 279481
This commit is contained in:
Bruno Cardoso Lopes 2016-08-22 21:50:22 +00:00
parent cc3dd629ee
commit 25f02cfc52
2 changed files with 18 additions and 0 deletions

View File

@ -11174,6 +11174,9 @@ TreeTransform<Derived>::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<SourceLocation, 16> SelLocs;
E->getSelectorLocs(SelLocs);

View File

@ -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