From: Erik Pilkington Date: Mon, 25 Feb 2019 21:35:14 +0000 (+0000) Subject: [CodeGenObjC] Fix a nullptr dyn_cast X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d7b99d69dacf627b59d32cbd9d97bdb46855c71;p=clang [CodeGenObjC] Fix a nullptr dyn_cast ObjCMessageExpr::getInstanceReceiver returns nullptr if the receiver is 'super'. Make this check more strict, since we don't care about messages to super here. rdar://48247290 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354826 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 1b3e71b436..fba1a531a2 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -433,8 +433,9 @@ tryEmitSpecializedAllocInit(CodeGenFunction &CGF, const ObjCMessageExpr *OME) { // Match the exact pattern '[[MyClass alloc] init]'. Selector Sel = OME->getSelector(); - if (!OME->isInstanceMessage() || !OME->getType()->isObjCObjectPointerType() || - !Sel.isUnarySelector() || Sel.getNameForSlot(0) != "init") + if (OME->getReceiverKind() != ObjCMessageExpr::Instance || + !OME->getType()->isObjCObjectPointerType() || !Sel.isUnarySelector() || + Sel.getNameForSlot(0) != "init") return None; // Okay, this is '[receiver init]', check if 'receiver' is '[cls alloc]'. diff --git a/test/CodeGenObjC/objc-alloc-init.m b/test/CodeGenObjC/objc-alloc-init.m index e56303c7fe..a55a9835c8 100644 --- a/test/CodeGenObjC/objc-alloc-init.m +++ b/test/CodeGenObjC/objc-alloc-init.m @@ -26,3 +26,16 @@ void f() { // EITHER: call {{.*}} @objc_msgSend } @end + +// rdar://48247290 +@interface Base +-(instancetype)init; +@end + +@interface Derived : Base +@end +@implementation Derived +-(void)meth { + [super init]; +} +@end