[PATCH] D89903: [CodeGen] Crash instead of generating broken code with self-capturing __block var
ille via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 08:50:27 PDT 2020
ille updated this revision to Diff 299998.
ille added a comment.
Move the check to cover the atomic case as well.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89903/new/
https://reviews.llvm.org/D89903
Files:
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGenCXX/block-capture-own-init.cpp
Index: clang/test/CodeGenCXX/block-capture-own-init.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/block-capture-own-init.cpp
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -x c++ -std=c++11 -fblocks -emit-llvm %s 2>&1 | FileCheck %s
+
+void test_aggregate_captured_by_own_init() {
+ struct foo { int a[100]; };
+ extern foo get_foo(foo *(^)());
+ // CHECK: error: cannot compile this aggregate initialized with potentially self-capturing block yet
+ __block foo f = get_foo(^{ return &f; });
+}
+
Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1913,6 +1913,11 @@
return;
}
case TEK_Aggregate:
+ if (capturedByInit) {
+ // TODO: how can we delay here if D is captured by its initializer?
+ CGM.ErrorUnsupported(
+ init, "aggregate initialized with potentially self-capturing block");
+ }
if (type->isAtomicType()) {
EmitAtomicInit(const_cast<Expr*>(init), lvalue);
} else {
@@ -1921,7 +1926,6 @@
Overlap = AggValueSlot::DoesNotOverlap;
else if (auto *FD = dyn_cast<FieldDecl>(D))
Overlap = getOverlapForFieldInit(FD);
- // TODO: how can we delay here if D is captured by its initializer?
EmitAggExpr(init, AggValueSlot::forLValue(
lvalue, *this, AggValueSlot::IsDestructed,
AggValueSlot::DoesNotNeedGCBarriers,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89903.299998.patch
Type: text/x-patch
Size: 1548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201022/c29aba34/attachment.bin>
More information about the cfe-commits
mailing list