BuildBot fix, compiler complains about array decay to pointer
[llvm-core.git] / utils / benchmark / test / state_assembly_test.cc
blobe2c5c8648d03556692033e520bcb982f00669d6a
1 #include <benchmark/benchmark.h>
3 #ifdef __clang__
4 #pragma clang diagnostic ignored "-Wreturn-type"
5 #endif
7 extern "C" {
8 extern int ExternInt;
9 benchmark::State& GetState();
10 void Fn();
13 using benchmark::State;
15 // CHECK-LABEL: test_for_auto_loop:
16 extern "C" int test_for_auto_loop() {
17 State& S = GetState();
18 int x = 42;
19 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
20 // CHECK-NEXT: testq %rbx, %rbx
21 // CHECK-NEXT: je [[LOOP_END:.*]]
23 for (auto _ : S) {
24 // CHECK: .L[[LOOP_HEAD:[a-zA-Z0-9_]+]]:
25 // CHECK-GNU-NEXT: subq $1, %rbx
26 // CHECK-CLANG-NEXT: {{(addq \$1,|incq)}} %rax
27 // CHECK-NEXT: jne .L[[LOOP_HEAD]]
28 benchmark::DoNotOptimize(x);
30 // CHECK: [[LOOP_END]]:
31 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
33 // CHECK: movl $101, %eax
34 // CHECK: ret
35 return 101;
38 // CHECK-LABEL: test_while_loop:
39 extern "C" int test_while_loop() {
40 State& S = GetState();
41 int x = 42;
43 // CHECK: j{{(e|mp)}} .L[[LOOP_HEADER:[a-zA-Z0-9_]+]]
44 // CHECK-NEXT: .L[[LOOP_BODY:[a-zA-Z0-9_]+]]:
45 while (S.KeepRunning()) {
46 // CHECK-GNU-NEXT: subq $1, %[[IREG:[a-z]+]]
47 // CHECK-CLANG-NEXT: {{(addq \$-1,|decq)}} %[[IREG:[a-z]+]]
48 // CHECK: movq %[[IREG]], [[DEST:.*]]
49 benchmark::DoNotOptimize(x);
51 // CHECK-DAG: movq [[DEST]], %[[IREG]]
52 // CHECK-DAG: testq %[[IREG]], %[[IREG]]
53 // CHECK-DAG: jne .L[[LOOP_BODY]]
54 // CHECK-DAG: .L[[LOOP_HEADER]]:
56 // CHECK: cmpb $0
57 // CHECK-NEXT: jne .L[[LOOP_END:[a-zA-Z0-9_]+]]
58 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
60 // CHECK: .L[[LOOP_END]]:
61 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
63 // CHECK: movl $101, %eax
64 // CHECK: ret
65 return 101;