1 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switchmacro.c %s | FileCheck %s
2 
3 #define FOO(x) (void)x
4 
5 // CHECK: foo
foo(int i)6 int foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:16 -> {{[0-9]+}}:2 = #0
7   switch (i) {   // CHECK-NEXT: Gap,File 0, [[@LINE]]:14 -> {{[0-9]+}}:11 = 0
8   default:       // CHECK-NEXT: File 0, [[@LINE]]:3 -> {{[0-9]+}}:11 = #2
9     if (i == 1)  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:15 = #2
10       return 0;  // CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = #3
11                  // CHECK-NEXT: File 0, [[@LINE-1]]:15 -> [[@LINE+3]]:5 = (#2 - #3)
12     // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:5 -> [[@LINE+2]]:8 = (#2 - #3) (Expanded file = 1)
13     // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> {{[0-9]+}}:11 = (#2 - #3)
14     FOO(1);
15   case 0:        // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:13 = ((#2 + #4) - #3)
16     return 2;    // CHECK-NEXT: Gap,File 0, [[@LINE]]:13 -> [[@LINE+6]]:3 = #5
17 
18   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:6 = 0
19   // CHECK-NEXT: File 0, [[@LINE+1]]:6 -> {{[0-9]+}}:11 = 0
20   FOO(1);
21   // CHECK-NEXT: File 0, [[@LINE+1]]:3 -> {{[0-9]+}}:11 = #5
22   label: ;
23   }
24 }
25 
26 // PR26825 - Crash when exiting macro expansion containing a switch
27 // CHECK: bar
28 #define START { while (0) { switch (0) {
29 #define END   }}}
bar()30 void bar() {
31   START      // CHECK: File 0, [[@LINE]]:8 -> [[@LINE+2]]:6
32 default: ;
33   END
34 }
35 
36 // PR27948 - Crash when handling a switch partially covered by a macro
37 // CHECK: baz
38 #define START2 switch (0) default:
baz()39 void baz() {
40   for (;;)
41     START2 return; // CHECK: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1 (Expanded file = 1)
42 }
43 
main(int argc,const char * argv[])44 int main(int argc, const char *argv[]) {
45   foo(3);
46   return 0;
47 }
48