brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · f18baea Raw
45 lines · c
1// Test that misexpect emits no warning when switch condition is non-const2 3// RUN: llvm-profdata merge %S/Inputs/misexpect-switch-nonconst.proftext -o %t.profdata4// RUN: %clang_cc1 %s -O2 -o - -disable-llvm-passes -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify5 6// expected-no-diagnostics7 8#define inner_loop 10009#define outer_loop 2010#define arry_size 2511 12int sum(int *buff, int size);13int random_sample(int *buff, int size);14int rand();15void init_arry();16 17int arry[arry_size] = {0};18 19int 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, 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 switch40    }   // end inner_loop41  }     // end outer_loop42 43  return 0;44}45