]> granicus.if.org Git - clang/commitdiff
Fix type mismatch assertion related to inalloca and PR19287
authorReid Kleckner <reid@kleckner.net>
Wed, 2 Apr 2014 00:16:53 +0000 (00:16 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 2 Apr 2014 00:16:53 +0000 (00:16 +0000)
Augment the test case from r205217 to catch this related bug.

Fixes the Windows self-host which was failing on VariantValue.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205378 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

index 430b56caa0ee20e207ff30247199243bc560c681..9db3c91a60aa5576b97a21309981cad1f89c2958 100644 (file)
@@ -1655,8 +1655,11 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg,
   CharUnits Align = getContext().getDeclAlign(&D);
   // If we already have a pointer to the argument, reuse the input pointer.
   if (ArgIsPointer) {
-    assert(isa<llvm::PointerType>(Arg->getType()));
-    DeclPtr = Arg;
+    // If we have a prettier pointer type at this point, bitcast to that.
+    unsigned AS = cast<llvm::PointerType>(Arg->getType())->getAddressSpace();
+    llvm::Type *IRTy = ConvertTypeForMem(Ty)->getPointerTo(AS);
+    DeclPtr = Arg->getType() == IRTy ? Arg : Builder.CreateBitCast(Arg, IRTy,
+                                                                   D.getName());
     // Push a destructor cleanup for this parameter if the ABI requires it.
     if (!IsScalar &&
         getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()) {
index 28b78b3dfe6e6b51c5d76f90698e95c5f50dd1b0..3d5fe9c9a1739bd8b9ecfbe7fde0034425b4177e 100644 (file)
@@ -270,16 +270,20 @@ void bar() {
 struct ForwardDeclare1;
 
 typedef void (*FnPtr1)(ForwardDeclare1);
-void fn1(FnPtr1, SmallWithDtor) {}
+void fn1(FnPtr1 a, SmallWithDtor b) { }
 
 struct ForwardDeclare1 {};
 
-void fn2() { fn1(0, SmallWithDtor()); };
-// WIN32-LABEL: define void @"\01?fn2@@YAXXZ"
-// WIN32:   %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]
+void fn2(FnPtr1 a, SmallWithDtor b) { fn1(a, b); };
+// WIN32-LABEL: define void @"\01?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
+// WIN32:   %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]* %{{.*}}, i32 0, i32 0
+// WIN32:   %[[a1:[^ ]*]] = bitcast {}** %[[a]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
+// WIN32:   %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
 // WIN32:   %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 1
-// WIN32:   call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"(%struct.SmallWithDtor* %[[gep1]])
+// WIN32:   %[[bc1:[^ ]*]] = bitcast %struct.SmallWithDtor* %[[gep1]] to i8*
+// WIN32:   call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[bc1]], i8* {{.*}}, i32 4, i32 4, i1 false)
+// WIN32:   %[[a2:[^ ]*]] = load void [[dst_ty]]* %[[a1]], align 4
 // WIN32:   %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 0
-// WIN32:   %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
-// WIN32:   store void [[dst_ty]] null, void [[dst_ty]]* %[[addr]], align 4
+// WIN32:   %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty]]*
+// WIN32:   store void [[dst_ty]] %[[a2]], void [[dst_ty]]* %[[addr]], align 4
 // WIN32:   call void @"\01?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"([[argmem_ty]]* inalloca %[[argmem]])