brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · ae13cf7 Raw
40 lines · c
1// Test that misexpect detects mis-annotated switch statements2 3// RUN: llvm-profdata merge %S/Inputs/misexpect-switch.proftext -o %t.profdata4// RUN: %clang_cc1 %s -O2 -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -verify -Wmisexpect -debug-info-kind=line-tables-only5 6#define inner_loop 10007#define outer_loop 208#define arry_size 259 10int arry[arry_size] = {0};11 12int rand();13int sum(int *buff, int size);14int random_sample(int *buff, int size);15 16int main() {17  int val = 0;18 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 switch35    }   // end inner_loop36  }     // end outer_loop37 38  return 0;39}40