xref: /llvm-project/clang/test/Profile/misexpect-switch-only-default-case.c (revision bac6cd5bf85669e3376610cfc4c4f9ca015e7b9b)
1 // Test that misexpect emits no warning when there is only one switch case
2 
3 // RUN: llvm-profdata merge %S/Inputs/misexpect-switch-default-only.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
5 
6 // expected-no-diagnostics
7 
8 #define inner_loop 1000
9 #define outer_loop 20
10 #define arry_size 25
11 
12 int sum(int *buff, int size);
13 int random_sample(int *buff, int size);
14 int rand();
15 void init_arry();
16 
17 int arry[arry_size] = {0};
18 
main()19 int main() {
20   init_arry();
21   int val = 0;
22 
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, 0)) {
28       default:
29         val += random_sample(arry, arry_size);
30         break;
31       }; // end switch
32     }    // end inner_loop
33   }      // end outer_loop
34 
35   return 0;
36 }
37