[PATCH] D43586: CodeGen: handle blocks correctly when inalloca'ed
Saleem Abdulrasool via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 21 10:20:52 PST 2018
compnerd created this revision.
compnerd added a reviewer: rnk.
Herald added a subscriber: cfe-commits.
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.
Repository:
rC Clang
https://reviews.llvm.org/D43586
Files:
lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/block-inalloca.cpp
Index: test/CodeGenCXX/block-inalloca.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/block-inalloca.cpp
@@ -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]]
+
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1850,7 +1850,10 @@
// The only implicit argument a block has is its literal.
// We assume this is always passed directly.
if (BlockInfo) {
- setBlockContextParameter(IPD, ArgNo, Arg.getDirectValue());
+ llvm::Value *V = Arg.isIndirect()
+ ? Builder.CreateLoad(Arg.getIndirectAddress())
+ : Arg.getDirectValue();
+ setBlockContextParameter(IPD, ArgNo, V);
return;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43586.135287.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180221/8ee2fc35/attachment.bin>
More information about the cfe-commits
mailing list