[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Profile / misexpect-switch-default.c
blobcd337b94301711d0dae4ad62febad1d6a393e720
1 // Test that misexpect detects mis-annotated switch statements for default case
3 // RUN: llvm-profdata merge %S/Inputs/misexpect-switch-default.proftext -o %t.profdata
4 // RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only
6 #define inner_loop 1000
7 #define outer_loop 20
8 #define arry_size 25
10 int sum(int *buff, int size);
11 int random_sample(int *buff, int size);
12 int rand();
13 void init_arry();
15 int arry[arry_size] = {0};
17 int main() {
18 init_arry();
19 int val = 0;
20 int j;
21 for (j = 0; j < outer_loop * inner_loop; ++j) {
22 unsigned condition = rand() % 5;
23 switch (__builtin_expect(condition, 6)) { // expected-warning-re {{potential performance regression from use of __builtin_expect(): annotation was correct on {{.+}}% ({{[0-9]+ / [0-9]+}}) of profiled executions}}
24 case 0:
25 val += sum(arry, arry_size);
26 break;
27 case 1:
28 case 2:
29 case 3:
30 break;
31 case 4:
32 val += random_sample(arry, arry_size);
33 break;
34 default:
35 __builtin_unreachable();
36 } // end switch
37 } // end outer_loop
39 return 0;