Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -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
     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
     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
     51 void test3() {
     52   int arr[] = {1, 2, 3, 4, 5};
     53   #pragma clang __debug captured
     54   {
     55     arr[2] = arr[1];
     56   }
     57   // CHECK-3: test3
     58   // CHECK-3: alloca [5 x i32]
     59   // CHECK-3: call void @__captured_stmt
     60 }
     61 
     62 void dont_capture_global() {
     63   static int s;
     64   extern int e;
     65   #pragma clang __debug captured
     66   {
     67     global++;
     68     s++;
     69     e++;
     70   }
     71 
     72   // CHECK-GLOBALS: %[[Capture:struct\.anon[\.0-9]*]] = type {}
     73   // CHECK-GLOBALS: call void @__captured_stmt[[HelperName:[0-9]+]](%[[Capture]]
     74 }
     75 
     76 // CHECK-GLOBALS: define internal void @__captured_stmt[[HelperName]]
     77 // CHECK-GLOBALS-NOT: ret
     78 // CHECK-GLOBALS:   load i32* @global
     79 // CHECK-GLOBALS:   load i32* @
     80 // CHECK-GLOBALS:   load i32* @e
     81