[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Profile / misexpect-switch.c
blob8ca8a155c74a745a2a68c964d69c05a6ac9b8f7d
1 // Test that misexpect detects mis-annotated switch statements
3 // RUN: llvm-profdata merge %S/Inputs/misexpect-switch.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 arry[arry_size] = {0};
12 int rand();
13 int sum(int *buff, int size);
14 int random_sample(int *buff, int size);
16 int main() {
17 int val = 0;
19 int j, k;
20 for (j = 0; j < outer_loop; ++j) {
21 for (k = 0; k < inner_loop; ++k) {
22 unsigned condition = rand() % 10000;
23 switch (__builtin_expect(condition, 0)) { // 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 default:
32 val += random_sample(arry, arry_size);
33 break;
34 } // end switch
35 } // end inner_loop
36 } // end outer_loop
38 return 0;