| 1 |
// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -DDEAD_CODE -fblocks -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s |
| 3 |
|
| 4 |
typedef void (^BlockTy)(void); |
| 5 |
void escapeFunc(BlockTy); |
| 6 |
typedef void (^BlockTy)(void); |
| 7 |
void noEscapeFunc(__attribute__((noescape)) BlockTy); |
| 8 |
|
| 9 |
// Verify that the desired DIExpression are generated for escaping (i.e, not |
| 10 |
// 'noescape') blocks. |
| 11 |
void test_escape_func(void) { |
| 12 |
// CHECK-LABEL: void @test_escape_func |
| 13 |
// CHECK: #dbg_declare({{.*}}![[ESCAPE_VAR:[0-9]+]], !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}}) |
| 14 |
__block int escape_var; |
| 15 |
// Blocks in dead code branches still capture __block variables. |
| 16 |
#ifdef DEAD_CODE |
| 17 |
if (0) |
| 18 |
#endif |
| 19 |
escapeFunc(^{ (void)escape_var; }); |
| 20 |
} |
| 21 |
|
| 22 |
// Verify that the desired DIExpression are generated for noescape blocks. |
| 23 |
void test_noescape_func(void) { |
| 24 |
// CHECK-LABEL: void @test_noescape_func |
| 25 |
// CHECK: #dbg_declare({{.*}}![[NOESCAPE_VAR:[0-9]+]], !DIExpression(), |
| 26 |
__block int noescape_var; |
| 27 |
noEscapeFunc(^{ (void)noescape_var; }); |
| 28 |
} |
| 29 |
|
| 30 |
// Verify that the desired DIExpression are generated for blocks. |
| 31 |
void test_local_block(void) { |
| 32 |
// CHECK-LABEL: void @test_local_block |
| 33 |
// CHECK: #dbg_declare({{.*}}![[BLOCK_VAR:[0-9]+]], !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}}) |
| 34 |
__block int block_var; |
| 35 |
|
| 36 |
// CHECK-LABEL: @__test_local_block_block_invoke |
| 37 |
// CHECK: #dbg_declare({{.*}}!DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}}) |
| 38 |
^ { block_var = 1; }(); |
| 39 |
} |
| 40 |
|
| 41 |
// Verify that the desired DIExpression are generated for __block vars not used |
| 42 |
// in any block. |
| 43 |
void test_unused(void) { |
| 44 |
// CHECK-LABEL: void @test_unused |
| 45 |
// CHECK: #dbg_declare({{.*}}![[UNUSED_VAR:[0-9]+]], !DIExpression(), |
| 46 |
__block int unused_var; |
| 47 |
// Use i (not inside a block). |
| 48 |
++unused_var; |
| 49 |
} |
| 50 |
|
| 51 |
// CHECK: ![[ESCAPE_VAR]] = !DILocalVariable(name: "escape_var" |
| 52 |
// CHECK: ![[NOESCAPE_VAR]] = !DILocalVariable(name: "noescape_var" |
| 53 |
// CHECK: ![[BLOCK_VAR]] = !DILocalVariable(name: "block_var" |
| 54 |
// CHECK: ![[UNUSED_VAR]] = !DILocalVariable(name: "unused_var" |
| 55 |
|