r279481 - [SemaObjC] Do not RebuildObjCMessageExpr without valid method decl

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 22 14:50:22 PDT 2016


Author: bruno
Date: Mon Aug 22 16:50:22 2016
New Revision: 279481

URL: http://llvm.org/viewvc/llvm-project?rev=279481&view=rev
Log:
[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

Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaObjC/call-super-2.m

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=279481&r1=279480&r2=279481&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Aug 22 16:50:22 2016
@@ -11174,6 +11174,9 @@ TreeTransform<Derived>::TransformObjCMes
   }
   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);

Modified: cfe/trunk/test/SemaObjC/call-super-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/call-super-2.m?rev=279481&r1=279480&r2=279481&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/call-super-2.m (original)
+++ cfe/trunk/test/SemaObjC/call-super-2.m Mon Aug 22 16:50:22 2016
@@ -106,3 +106,18 @@ id objc_getClass(const char *s);
 }
 @end
 
+ at class C;
+ at interface A // expected-note {{receiver is instance of class declared here}}
+- (instancetype)initWithCoder:(A *)coder;
+ at end
+
+ at interface B : A
+ at end
+
+ at 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;
+}
+ at end




More information about the cfe-commits mailing list