Author: compnerd Date: Wed Feb 21 13:47:51 2018 New Revision: 325724 URL: http://llvm.org/viewvc/llvm-project?rev=325724&view=rev Log: CodeGen: handle blocks correctly when inalloca'ed
When using blocks with C++ on Windows x86, it is possible to have the block literal be pushed into the inalloca'ed parameters. Teach IRGen to handle the case properly by extracting the block literal from the inalloca parameter. This fixes the use of blocks with C++ on Windows x86. Added: cfe/trunk/test/CodeGenCXX/block-inalloca.cpp Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=325724&r1=325723&r2=325724&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Feb 21 13:47:51 2018 @@ -1848,9 +1848,12 @@ void CodeGenFunction::EmitParmDecl(const // Use better IR generation for certain implicit parameters. if (auto IPD = dyn_cast<ImplicitParamDecl>(&D)) { // The only implicit argument a block has is its literal. - // We assume this is always passed directly. + // This may be passed as an inalloca'ed value on Windows x86. if (BlockInfo) { - setBlockContextParameter(IPD, ArgNo, Arg.getDirectValue()); + llvm::Value *V = Arg.isIndirect() + ? Builder.CreateLoad(Arg.getIndirectAddress()) + : Arg.getDirectValue(); + setBlockContextParameter(IPD, ArgNo, V); return; } } Added: cfe/trunk/test/CodeGenCXX/block-inalloca.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/block-inalloca.cpp?rev=325724&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/block-inalloca.cpp (added) +++ cfe/trunk/test/CodeGenCXX/block-inalloca.cpp Wed Feb 21 13:47:51 2018 @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fblocks -emit-llvm -o - %s | FileCheck %s + +struct S { + S(const struct S &) {} +}; + +void (^b)(S) = ^(S) {}; + +// CHECK: [[DESCRIPTOR:%.*]] = getelementptr inbounds <{ i8*, %struct.S, [3 x i8] }>, <{ i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 0 +// CHECK: load i8*, i8** [[DESCRIPTOR]] + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits