From: Reid Kleckner Date: Wed, 2 Apr 2014 00:16:53 +0000 (+0000) Subject: Fix type mismatch assertion related to inalloca and PR19287 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d17790ee00f645acf556e330935814291d378b11;p=clang Fix type mismatch assertion related to inalloca and PR19287 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 --- diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 430b56caa0..9db3c91a60 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -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(Arg->getType())); - DeclPtr = Arg; + // If we have a prettier pointer type at this point, bitcast to that. + unsigned AS = cast(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()) { diff --git a/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp b/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp index 28b78b3dfe..3d5fe9c9a1 100644 --- a/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp +++ b/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp @@ -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]])