• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o %t
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 
7 int foo();
8 int global;
9 
10 // Single statement
test1()11 void test1() {
12   int i = 0;
13   #pragma clang __debug captured
14   {
15     i++;
16   }
17   // CHECK-1: %struct.anon = type { i32* }
18   //
19   // CHECK-1: test1
20   // CHECK-1: alloca %struct.anon
21   // CHECK-1: getelementptr inbounds %struct.anon*
22   // CHECK-1: store i32* %i
23   // CHECK-1: call void @[[HelperName:__captured_stmt[0-9]+]]
24 }
25 
26 // CHECK-1: define internal void @[[HelperName]](%struct.anon
27 // CHECK-1:   getelementptr inbounds %struct.anon{{.*}}, i32 0, i32 0
28 // CHECK-1:   load i32**
29 // CHECK-1:   load i32*
30 // CHECK-1:   add nsw i32
31 // CHECK-1:   store i32
32 
33 // Compound statement with local variable
test2(int x)34 void test2(int x) {
35   #pragma clang __debug captured
36   {
37     int i;
38     for (i = 0; i < x; i++)
39       foo();
40   }
41   // CHECK-2: test2
42   // CHECK-2-NOT: %i
43   // CHECK-2: call void @[[HelperName:__captured_stmt[0-9]+]]
44 }
45 
46 // CHECK-2: define internal void @[[HelperName]]
47 // CHECK-2-NOT: }
48 // CHECK-2:   %i = alloca i32
49 
50 // Capture array
test3(int size)51 void test3(int size) {
52   int arr[] = {1, 2, 3, 4, 5};
53   int vla_arr[size];
54   #pragma clang __debug captured
55   {
56     arr[2] = vla_arr[size - 1];
57   }
58   // CHECK-3: test3
59   // CHECK-3: alloca [5 x i32]
60   // CHECK-3: call void @__captured_stmt
61 }
62 
63 // Capture VLA array
test4(int size,int vla_arr[size])64 void test4(int size, int vla_arr[size]) {
65   #pragma clang __debug captured
66   {
67     vla_arr[0] = 1;
68   }
69   // CHECK-3: test4([[INT:i.+]] {{.*}}[[SIZE:%.+]], [[INT]]*
70   // CHECK-3: store [[INT]] {{.*}}[[SIZE]], [[INT]]* [[SIZE_ADDR:%.+]],
71   // CHECK-3: [[REF:%.+]] = getelementptr inbounds
72   // CHECK-3: store [[INT]]* [[SIZE_ADDR]], [[INT]]** [[REF]]
73   // CHECK-3: call void @__captured_stmt
74 }
75 
dont_capture_global()76 void dont_capture_global() {
77   static int s;
78   extern int e;
79   #pragma clang __debug captured
80   {
81     global++;
82     s++;
83     e++;
84   }
85 
86   // CHECK-GLOBALS: %[[Capture:struct\.anon[\.0-9]*]] = type {}
87   // CHECK-GLOBALS: call void @__captured_stmt[[HelperName:[0-9]+]](%[[Capture]]
88 }
89 
90 // CHECK-GLOBALS: define internal void @__captured_stmt[[HelperName]]
91 // CHECK-GLOBALS-NOT: ret
92 // CHECK-GLOBALS:   load i32* @global
93 // CHECK-GLOBALS:   load i32* @
94 // CHECK-GLOBALS:   load i32* @e
95