summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-08-22 21:50:22 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-08-22 21:50:22 +0000
commit25f02cfc52c7adfa76a45bc6a8063a675a5e6c5d (patch)
tree480a8b3d71f8457d1b2c43adad67be47921f508d
parentcc3dd629eedb3b5a4f74bf2e0c3729c211d79df7 (diff)
downloadbcm5719-llvm-25f02cfc52c7adfa76a45bc6a8063a675a5e6c5d.tar.gz
bcm5719-llvm-25f02cfc52c7adfa76a45bc6a8063a675a5e6c5d.zip
[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
-rw-r--r--clang/lib/Sema/TreeTransform.h3
-rw-r--r--clang/test/SemaObjC/call-super-2.m15
2 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 8ea0b015e5f..c53505d10ab 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -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);
diff --git a/clang/test/SemaObjC/call-super-2.m b/clang/test/SemaObjC/call-super-2.m
index 8927f3b5286..01acff70c23 100644
--- a/clang/test/SemaObjC/call-super-2.m
+++ b/clang/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
OpenPOWER on IntegriCloud