forked from OSchip/llvm-project
When copy-capturing values for a nested capture, use a BlockDeclRefExpr.
llvm-svn: 125021
This commit is contained in:
parent
389971b318
commit
93be3f75cc
|
@ -583,10 +583,18 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
|
||||||
|
|
||||||
// Otherwise, fake up a POD copy into the block field.
|
// Otherwise, fake up a POD copy into the block field.
|
||||||
} else {
|
} else {
|
||||||
DeclRefExpr declRef(const_cast<VarDecl*>(variable), type, VK_LValue,
|
// We use one of these or the other depending on whether the
|
||||||
SourceLocation());
|
// reference is nested.
|
||||||
|
DeclRefExpr notNested(const_cast<VarDecl*>(variable), type, VK_LValue,
|
||||||
|
SourceLocation());
|
||||||
|
BlockDeclRefExpr nested(const_cast<VarDecl*>(variable), type,
|
||||||
|
VK_LValue, SourceLocation(), /*byref*/ false);
|
||||||
|
|
||||||
|
Expr *declRef =
|
||||||
|
(ci->isNested() ? static_cast<Expr*>(&nested) : ¬Nested);
|
||||||
|
|
||||||
ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue,
|
ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue,
|
||||||
&declRef, VK_RValue);
|
declRef, VK_RValue);
|
||||||
EmitAnyExprToMem(&l2r, blockField, /*volatile*/ false, /*init*/ true);
|
EmitAnyExprToMem(&l2r, blockField, /*volatile*/ false, /*init*/ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
|
||||||
|
|
||||||
|
namespace test0 {
|
||||||
|
// CHECK: define void @_ZN5test04testEi(
|
||||||
|
// CHECK: define internal void @__test_block_invoke_{{.*}}(
|
||||||
|
// CHECK: define internal void @__block_global_{{.*}}(
|
||||||
|
void test(int x) {
|
||||||
|
^{ ^{ (void) x; }; };
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue