r306494 - [CodeGen] Fix assertion failure in EmitCallArg.

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 27 17:42:48 PDT 2017


Author: ahatanak
Date: Tue Jun 27 17:42:48 2017
New Revision: 306494

URL: http://llvm.org/viewvc/llvm-project?rev=306494&view=rev
Log:
[CodeGen] Fix assertion failure in EmitCallArg.

The assertion was failing when a method of a parameterized class was
called and the types of the argument and parameter didn't match. To fix
the failure, move the assertion in EmitCallArg to its only caller
EmitCallArgs and require the argument and parameter types match only
when the method is not parameterized.

rdar://problem/32874473

Differential Revision: https://reviews.llvm.org/D34665

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenObjC/parameterized_classes.m

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=306494&r1=306493&r2=306494&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Jun 27 17:42:48 2017
@@ -3389,6 +3389,14 @@ void CodeGenFunction::EmitCallArgs(
     unsigned Idx = LeftToRight ? I : E - I - 1;
     CallExpr::const_arg_iterator Arg = ArgRange.begin() + Idx;
     unsigned InitialArgSize = Args.size();
+    // If *Arg is an ObjCIndirectCopyRestoreExpr, check that either the types of
+    // the argument and parameter match or the objc method is parameterized.
+    assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
+            getContext().hasSameUnqualifiedType((*Arg)->getType(),
+                                                ArgTypes[Idx]) ||
+            (isa<ObjCMethodDecl>(AC.getDecl()) &&
+             isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.getDecl())))) &&
+           "Argument and parameter types don't match");
     EmitCallArg(Args, *Arg, ArgTypes[Idx]);
     // In particular, we depend on it being the last arg in Args, and the
     // objectsize bits depend on there only being one arg if !LeftToRight.
@@ -3449,7 +3457,6 @@ void CodeGenFunction::EmitCallArg(CallAr
   if (const ObjCIndirectCopyRestoreExpr *CRE
         = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
     assert(getLangOpts().ObjCAutoRefCount);
-    assert(getContext().hasSameUnqualifiedType(E->getType(), type));
     return emitWritebackArg(*this, args, CRE);
   }
 

Modified: cfe/trunk/test/CodeGenObjC/parameterized_classes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/parameterized_classes.m?rev=306494&r1=306493&r2=306494&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/parameterized_classes.m (original)
+++ cfe/trunk/test/CodeGenObjC/parameterized_classes.m Tue Jun 27 17:42:48 2017
@@ -96,3 +96,31 @@ void blockTest(NSMutableArray<void (^)(v
   _destination = a;
 }
 @end
+
+// CHECK-LABEL: define internal void @"\01-[C0 foo1]"(
+// CHECK: {{.*}} = alloca
+// CHECK: {{.*}} = alloca
+// CHECK: %[[D:.*]] = alloca %[[TY:.*]]*
+// CHECK: %[[TEMP:.*]] = alloca %[[TY]]*
+// CHECK: %[[V4:.*]] = load %[[TY]]*, %[[TY]]** %[[D]]
+// CHECK: store %[[TY]]* %[[V4]], %[[TY]]** %[[TEMP]]
+// CHECK: %[[V7:.*]] = bitcast %[[TY]]** %[[TEMP]] to i8**
+// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8**)*)(i8* %{{.*}}, i8* %{{.*}}, i8** %[[V7]])
+
+ at interface P0<ObjectType> : NSObject
+- (void)m0:(ObjectType *)first;
+ at end
+
+ at interface C0 : NSObject
+-(void)foo1;
+ at end
+
+ at implementation C0 {
+  P0<NSString *> *x;
+}
+
+-(void)foo1 {
+  NSString *d;
+  [x m0:&d];
+}
+ at end




More information about the cfe-commits mailing list