summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2019-02-08 01:29:17 +0000
committerJF Bastien <jfbastien@apple.com>2019-02-08 01:29:17 +0000
commitb347e752580961136913f7e076befd8e83d02cb7 (patch)
treec85b1c97d26b009c9c320960df2ebdaec76589f2 /clang/test
parent0719b3527f5bc550d3677161ca49a0e6d462c9e1 (diff)
downloadbcm5719-llvm-b347e752580961136913f7e076befd8e83d02cb7.tar.gz
bcm5719-llvm-b347e752580961136913f7e076befd8e83d02cb7.zip
Variable auto-init: fix __block initialization
Summary: Automatic initialization [1] of __block variables was trampling over the block's headers after they'd been initialized, which caused self-init usage to crash, such as here: typedef struct XYZ { void (^block)(); } *xyz_t; __attribute__((noinline)) xyz_t create(void (^block)()) { xyz_t myself = malloc(sizeof(struct XYZ)); myself->block = block; return myself; } int main() { __block xyz_t captured = create(^(){ (void)captured; }); } This type of code shouldn't be broken by variable auto-init, even if it's sketchy. [1] With -ftrivial-auto-var-init=pattern <rdar://problem/47798396> Reviewers: rjmccall, pcc, kcc Subscribers: jkorous, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57797 llvm-svn: 353495
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGenCXX/trivial-auto-var-init.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/trivial-auto-var-init.cpp b/clang/test/CodeGenCXX/trivial-auto-var-init.cpp
index b795c0755bd..37ff770abf5 100644
--- a/clang/test/CodeGenCXX/trivial-auto-var-init.cpp
+++ b/clang/test/CodeGenCXX/trivial-auto-var-init.cpp
@@ -30,6 +30,32 @@ void test_block() {
used(block);
}
+// Using the variable being initialized is typically UB in C, but for blocks we
+// can be nice: they imply extra book-keeping and we can do the auto-init before
+// any of said book-keeping.
+//
+// UNINIT-LABEL: test_block_self_init(
+// ZERO-LABEL: test_block_self_init(
+// ZERO: %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
+// ZERO: %captured1 = getelementptr inbounds %struct.__block_byref_captured, %struct.__block_byref_captured* %captured, i32 0, i32 4
+// ZERO-NEXT: store %struct.XYZ* null, %struct.XYZ** %captured1, align 8
+// ZERO: %call = call %struct.XYZ* @create(
+// PATTERN-LABEL: test_block_self_init(
+// PATTERN: %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
+// PATTERN: %captured1 = getelementptr inbounds %struct.__block_byref_captured, %struct.__block_byref_captured* %captured, i32 0, i32 4
+// PATTERN-NEXT: store %struct.XYZ* inttoptr (i64 -6148914691236517206 to %struct.XYZ*), %struct.XYZ** %captured1, align 8
+// PATTERN: %call = call %struct.XYZ* @create(
+void test_block_self_init() {
+ using Block = void (^)();
+ typedef struct XYZ {
+ Block block;
+ } * xyz_t;
+ extern xyz_t create(Block block);
+ __block xyz_t captured = create(^() {
+ (void)captured;
+ });
+}
+
// This type of code is currently not handled by zero / pattern initialization.
// The test will break when that is fixed.
// UNINIT-LABEL: test_goto_unreachable_value(
OpenPOWER on IntegriCloud