[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Profile / misexpect-switch-nonconst.c
blobcff3bce0d6d0a1d174d0b8d25f2fa149655721c0
1 // Test that misexpect emits no warning when switch condition is non-const
3 // RUN: llvm-profdata merge %S/Inputs/misexpect-switch-nonconst.proftext -o %t.profdata
4 // RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use-path=%t.profdata -verify
6 // expected-no-diagnostics
8 #define inner_loop 1000
9 #define outer_loop 20
10 #define arry_size 25
12 int sum(int *buff, int size);
13 int random_sample(int *buff, int size);
14 int rand();
15 void init_arry();
17 int arry[arry_size] = {0};
19 int main() {
20 init_arry();
21 int val = 0;
23 int j, k;
24 for (j = 0; j < outer_loop; ++j) {
25 for (k = 0; k < inner_loop; ++k) {
26 unsigned condition = rand() % 10000;
27 switch (__builtin_expect(condition, rand())) {
28 case 0:
29 val += sum(arry, arry_size);
30 break;
31 case 1:
32 case 2:
33 case 3:
34 case 4:
35 val += random_sample(arry, arry_size);
36 break;
37 default:
38 __builtin_unreachable();
39 } // end switch
40 } // end inner_loop
41 } // end outer_loop
43 return 0;