diff options
| -rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 7 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp | 18 |
2 files changed, 16 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 430b56caa0e..9db3c91a60a 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/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<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()) { diff --git a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp index 28b78b3dfe6..3d5fe9c9a17 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp +++ b/clang/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]]) |

