Home | History | Annotate | Download | only in CoverageMapping
      1 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroscopes.cpp %s | FileCheck %s
      2 
      3 #define starts_a_scope for (int i = 0; i < 2; ++i) {
      4 
      5 #define ends_a_scope \
      6   x = x;             \
      7   }
      8 
      9 #define some_code \
     10   x = x;          \
     11   if (x == 0) {   \
     12     x = 1;        \
     13   } else {        \
     14     x = 2;        \
     15   }               \
     16   if (true) {     \
     17     x = x;        \
     18   } else {        \
     19     x = x;        \
     20   }
     21 
     22 #define starts_a_while while (x < 5)
     23 #define simple_stmt ++x
     24 
     25 #define macro_with_for          \
     26   x = 3;                        \
     27   for (int i = 0; i < x; ++i) { \
     28   }
     29 
     30 #define macro_with_while \
     31   x = 4;                 \
     32   while (x < 5) {        \
     33     ++x;                 \
     34   }
     35 
     36 // CHECK: main
     37 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
     38 int main() {
     39   int x = 0;
     40   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:17 = #0
     41   // CHECK-NEXT: File 0, [[@LINE+1]]:17 -> [[@LINE+7]]:15 = #1
     42   starts_a_scope
     43     x = x;
     44     // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:5 -> [[@LINE+1]]:14 = #1
     45     some_code
     46     x = x;
     47   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:15 = #1
     48   ends_a_scope
     49 
     50   // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:3 -> [[@LINE+4]]:17 = #0
     51   // CHECK-NEXT: File 0, [[@LINE+3]]:17 -> [[@LINE+5]]:15 = #4
     52   // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:5 -> [[@LINE+3]]:14 = #4
     53   // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:3 -> [[@LINE+3]]:15 = #4
     54   starts_a_scope
     55     some_code
     56   ends_a_scope
     57 
     58   // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:3 -> [[@LINE+3]]:17 = #0
     59   // CHECK-NEXT: File 0, [[@LINE+2]]:17 -> [[@LINE+3]]:15 = #7
     60   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:15 = #7
     61   starts_a_scope
     62   ends_a_scope
     63 
     64   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:17 = #0
     65   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:5 -> [[@LINE+2]]:16 = #8
     66   starts_a_while
     67     simple_stmt;
     68 
     69   x = 0;
     70   // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:3 -> [[@LINE+4]]:17 = #0
     71   // CHECK-NEXT: File 0, [[@LINE+3]]:18 -> [[@LINE+5]]:15 = #9
     72   // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:5 -> [[@LINE+3]]:16 = #9
     73   // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:3 -> [[@LINE+3]]:15 = #9
     74   starts_a_while {
     75     simple_stmt;
     76   ends_a_scope
     77 
     78   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
     79   macro_with_for
     80   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
     81   macro_with_while
     82 
     83   return 0;
     84 }
     85 
     86 // CHECK-NEXT: File 1, 3:24 -> 3:53 = #0
     87 // CHECK-NEXT: File 1, 3:40 -> 3:45 = (#0 + #1)
     88 // CHECK-NEXT: File 1, 3:47 -> 3:50 = #1
     89 // CHECK-NEXT: File 1, 3:52 -> 3:53 = #1
     90 // CHECK-NEXT: File 2, 10:3 -> 20:4 = #1
     91 // CHECK-NEXT: File 2, 11:7 -> 11:13 = #1
     92 // CHECK-NEXT: File 2, 11:15 -> 13:4 = #2
     93 // CHECK-NEXT: File 2, 13:10 -> 15:4 = (#1 - #2)
     94 // CHECK-NEXT: File 2, 16:7 -> 16:11 = #1
     95 // CHECK-NEXT: File 2, 16:13 -> 18:4 = #3
     96 // CHECK-NEXT: File 2, 18:10 -> 20:4 = (#1 - #3)
     97 // CHECK-NEXT: File 3, 6:3 -> 7:4 = #1
     98 // CHECK-NEXT: File 4, 3:24 -> 3:53 = #0
     99 // CHECK-NEXT: File 4, 3:40 -> 3:45 = (#0 + #4)
    100 // CHECK-NEXT: File 4, 3:47 -> 3:50 = #4
    101 // CHECK-NEXT: File 4, 3:52 -> 3:53 = #4
    102 // CHECK-NEXT: File 5, 10:3 -> 20:4 = #4
    103 // CHECK-NEXT: File 5, 11:7 -> 11:13 = #4
    104 // CHECK-NEXT: File 5, 11:15 -> 13:4 = #5
    105 // CHECK-NEXT: File 5, 13:10 -> 15:4 = (#4 - #5)
    106 // CHECK-NEXT: File 5, 16:7 -> 16:11 = #4
    107 // CHECK-NEXT: File 5, 16:13 -> 18:4 = #6
    108 // CHECK-NEXT: File 5, 18:10 -> 20:4 = (#4 - #6)
    109 // CHECK-NEXT: File 6, 6:3 -> 7:4 = #4
    110 // CHECK-NEXT: File 7, 3:24 -> 3:53 = #0
    111 // CHECK-NEXT: File 7, 3:40 -> 3:45 = (#0 + #7)
    112 // CHECK-NEXT: File 7, 3:47 -> 3:50 = #7
    113 // CHECK-NEXT: File 7, 3:52 -> 3:53 = #7
    114 // CHECK-NEXT: File 8, 6:3 -> 7:4 = #7
    115 // CHECK-NEXT: File 9, 22:24 -> 22:37 = #0
    116 // CHECK-NEXT: File 9, 22:31 -> 22:36 = (#0 + #8)
    117 // CHECK-NEXT: File 10, 23:21 -> 23:24 = #8
    118 // CHECK-NEXT: File 11, 22:24 -> 22:37 = #0
    119 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
    120 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
    121 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
    122 // CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
    123 // CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
    124 // CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
    125 // CHECK-NEXT: File 14, 27:31 -> 28:4 = #10
    126 // CHECK-NEXT: File 15, 31:3 -> 34:4 = #0
    127 // CHECK-NEXT: File 15, 32:10 -> 32:15 = (#0 + #11)
    128 // CHECK-NEXT: File 15, 32:17 -> 34:4 = #11
    129