xref: /minix3/external/bsd/llvm/dist/clang/test/CoverageMapping/switch.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.c %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc                     // CHECK: foo
foo(int i)3*0a6a1f1dSLionel Sambuc void foo(int i) {   // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 (HasCodeBefore = 0)
4*0a6a1f1dSLionel Sambuc   switch(i) {
5*0a6a1f1dSLionel Sambuc   case 1:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = #2 (HasCodeBefore = 0)
6*0a6a1f1dSLionel Sambuc     return;
7*0a6a1f1dSLionel Sambuc   case 2:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3 (HasCodeBefore = 0)
8*0a6a1f1dSLionel Sambuc     break;
9*0a6a1f1dSLionel Sambuc   }                 // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:12 = #1 (HasCodeBefore = 0)
10*0a6a1f1dSLionel Sambuc   int x = 0;
11*0a6a1f1dSLionel Sambuc }
12*0a6a1f1dSLionel Sambuc 
13*0a6a1f1dSLionel Sambuc                     // CHECK-NEXT: main
main()14*0a6a1f1dSLionel Sambuc int main() {        // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 = #0 (HasCodeBefore = 0)
15*0a6a1f1dSLionel Sambuc   int i = 0;
16*0a6a1f1dSLionel Sambuc   switch(i) {
17*0a6a1f1dSLionel Sambuc   case 0:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #2 (HasCodeBefore = 0)
18*0a6a1f1dSLionel Sambuc     i = 1;
19*0a6a1f1dSLionel Sambuc     break;
20*0a6a1f1dSLionel Sambuc   case 1:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #3 (HasCodeBefore = 0)
21*0a6a1f1dSLionel Sambuc     i = 2;
22*0a6a1f1dSLionel Sambuc     break;
23*0a6a1f1dSLionel Sambuc   default:          // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 (HasCodeBefore = 0)
24*0a6a1f1dSLionel Sambuc     break;
25*0a6a1f1dSLionel Sambuc   }                 // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:14 = #1 (HasCodeBefore = 0)
26*0a6a1f1dSLionel Sambuc   switch(i) {
27*0a6a1f1dSLionel Sambuc   case 0:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #6 (HasCodeBefore = 0)
28*0a6a1f1dSLionel Sambuc     i = 1;
29*0a6a1f1dSLionel Sambuc     break;
30*0a6a1f1dSLionel Sambuc   case 1:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #7 (HasCodeBefore = 0)
31*0a6a1f1dSLionel Sambuc     i = 2;
32*0a6a1f1dSLionel Sambuc   default:          // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = (#7 + #8) (HasCodeBefore = 0)
33*0a6a1f1dSLionel Sambuc     break;
34*0a6a1f1dSLionel Sambuc   }                 // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:14 = #5 (HasCodeBefore = 0)
35*0a6a1f1dSLionel Sambuc 
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc   switch(i) {
38*0a6a1f1dSLionel Sambuc   case 1:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:10 = #10 (HasCodeBefore = 0)
39*0a6a1f1dSLionel Sambuc   case 2:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (#10 + #11) (HasCodeBefore = 0)
40*0a6a1f1dSLionel Sambuc     i = 11;
41*0a6a1f1dSLionel Sambuc   case 3:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:10 = ((#10 + #11) + #12) (HasCodeBefore = 0)
42*0a6a1f1dSLionel Sambuc   case 4:           // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13) (HasCodeBefore = 0)
43*0a6a1f1dSLionel Sambuc     i = 99;
44*0a6a1f1dSLionel Sambuc   }                 // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9 (HasCodeBefore = 0)
45*0a6a1f1dSLionel Sambuc 
46*0a6a1f1dSLionel Sambuc   foo(1);
47*0a6a1f1dSLionel Sambuc   return 0;
48*0a6a1f1dSLionel Sambuc }
49