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,
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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits