Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o %t |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 2 | // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-GLOBALS |
| 3 | // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-1 |
| 4 | // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-2 |
| 5 | // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-3 |
| 6 | |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 7 | typedef __INTPTR_TYPE__ intptr_t; |
| 8 | |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 9 | int foo(); |
| 10 | int global; |
| 11 | |
| 12 | // Single statement |
| 13 | void test1() { |
| 14 | int i = 0; |
| 15 | #pragma clang __debug captured |
| 16 | { |
Alexey Bataev | 43f7439 | 2015-05-07 06:28:46 +0000 | [diff] [blame] | 17 | static float inner = 3.0; |
| 18 | (void)inner; |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 19 | i++; |
| 20 | } |
| 21 | // CHECK-1: %struct.anon = type { i32* } |
Alexey Bataev | 43f7439 | 2015-05-07 06:28:46 +0000 | [diff] [blame] | 22 | // CHECK-1: {{.+}} global float 3.0 |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 23 | // |
| 24 | // CHECK-1: test1 |
| 25 | // CHECK-1: alloca %struct.anon |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 26 | // CHECK-1: getelementptr inbounds %struct.anon, %struct.anon* |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 27 | // CHECK-1: store i32* %i |
Sunil Srivastava | 3acf627 | 2015-05-12 16:48:43 +0000 | [diff] [blame] | 28 | // CHECK-1: call void @[[HelperName:__captured_stmt[\.0-9]+]] |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 29 | } |
| 30 | |
David Blaikie | ea3e51d | 2015-06-29 17:29:50 +0000 | [diff] [blame] | 31 | // CHECK-1: define internal {{.*}}void @[[HelperName]](%struct.anon |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 32 | // CHECK-1: getelementptr inbounds %struct.anon{{.*}}, i32 0, i32 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 33 | // CHECK-1: load i32*, i32** |
| 34 | // CHECK-1: load i32, i32* |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 35 | // CHECK-1: add nsw i32 |
| 36 | // CHECK-1: store i32 |
| 37 | |
| 38 | // Compound statement with local variable |
| 39 | void test2(int x) { |
| 40 | #pragma clang __debug captured |
| 41 | { |
| 42 | int i; |
| 43 | for (i = 0; i < x; i++) |
| 44 | foo(); |
| 45 | } |
| 46 | // CHECK-2: test2 |
| 47 | // CHECK-2-NOT: %i |
Sunil Srivastava | 3acf627 | 2015-05-12 16:48:43 +0000 | [diff] [blame] | 48 | // CHECK-2: call void @[[HelperName:__captured_stmt[\.0-9]+]] |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 49 | } |
| 50 | |
David Blaikie | ea3e51d | 2015-06-29 17:29:50 +0000 | [diff] [blame] | 51 | // CHECK-2: define internal {{.*}}void @[[HelperName]] |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 52 | // CHECK-2-NOT: } |
| 53 | // CHECK-2: %i = alloca i32 |
| 54 | |
| 55 | // Capture array |
Alexey Bataev | aca7fcf | 2014-06-30 02:55:54 +0000 | [diff] [blame] | 56 | void test3(int size) { |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 57 | int arr[] = {1, 2, 3, 4, 5}; |
Alexey Bataev | aca7fcf | 2014-06-30 02:55:54 +0000 | [diff] [blame] | 58 | int vla_arr[size]; |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 59 | #pragma clang __debug captured |
| 60 | { |
Alexey Bataev | aca7fcf | 2014-06-30 02:55:54 +0000 | [diff] [blame] | 61 | arr[2] = vla_arr[size - 1]; |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 62 | } |
| 63 | // CHECK-3: test3 |
| 64 | // CHECK-3: alloca [5 x i32] |
| 65 | // CHECK-3: call void @__captured_stmt |
| 66 | } |
| 67 | |
Alexey Bataev | f94baeb | 2014-07-02 07:05:22 +0000 | [diff] [blame] | 68 | // Capture VLA array |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 69 | void test4(intptr_t size, intptr_t vla_arr[size]) { |
Alexey Bataev | f94baeb | 2014-07-02 07:05:22 +0000 | [diff] [blame] | 70 | #pragma clang __debug captured |
| 71 | { |
| 72 | vla_arr[0] = 1; |
| 73 | } |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 74 | // CHECK-3: test4([[INTPTR_T:i.+]] {{.*}}[[SIZE_ARG:%.+]], [[INTPTR_T]]* |
| 75 | // CHECK-3: store [[INTPTR_T]] {{.*}}[[SIZE_ARG]], [[INTPTR_T]]* [[SIZE_ADDR:%.+]], |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 76 | // CHECK-3: [[SIZE:%.+]] = load [[INTPTR_T]], [[INTPTR_T]]* [[SIZE_ADDR]], |
Alexey Bataev | f94baeb | 2014-07-02 07:05:22 +0000 | [diff] [blame] | 77 | // CHECK-3: [[REF:%.+]] = getelementptr inbounds |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 78 | // CHECK-3: store [[INTPTR_T]] [[SIZE]], [[INTPTR_T]]* [[REF]] |
Alexey Bataev | f94baeb | 2014-07-02 07:05:22 +0000 | [diff] [blame] | 79 | // CHECK-3: call void @__captured_stmt |
| 80 | } |
| 81 | |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 82 | void dont_capture_global() { |
| 83 | static int s; |
| 84 | extern int e; |
| 85 | #pragma clang __debug captured |
| 86 | { |
| 87 | global++; |
| 88 | s++; |
| 89 | e++; |
| 90 | } |
| 91 | |
| 92 | // CHECK-GLOBALS: %[[Capture:struct\.anon[\.0-9]*]] = type {} |
Sunil Srivastava | 3acf627 | 2015-05-12 16:48:43 +0000 | [diff] [blame] | 93 | // CHECK-GLOBALS: call void @__captured_stmt[[HelperName:[\.0-9]+]](%[[Capture]] |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 94 | } |
| 95 | |
David Blaikie | ea3e51d | 2015-06-29 17:29:50 +0000 | [diff] [blame] | 96 | // CHECK-GLOBALS: define internal {{.*}}void @__captured_stmt[[HelperName]] |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 97 | // CHECK-GLOBALS-NOT: ret |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 98 | // CHECK-GLOBALS: load i32, i32* @global |
| 99 | // CHECK-GLOBALS: load i32, i32* @ |
| 100 | // CHECK-GLOBALS: load i32, i32* @e |