1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // Check that the condition register is restored properly during unwinding |
10 | // on AIX. Option -O3 is required so that the compiler will re-use the value |
11 | // in the condition register instead of re-evaluating the condition expression. |
12 | |
13 | // REQUIRES: target=powerpc{{(64)?}}-ibm-aix |
14 | // ADDITIONAL_COMPILE_FLAGS: -O3 |
15 | // UNSUPPORTED: no-exceptions |
16 | |
17 | #include <cstdlib> |
18 | #include <cassert> |
19 | |
20 | int __attribute__((noinline)) test2(int i) { |
21 | // The inline assembly forces the prologue/epilogue to save/restore the |
22 | // condition register. |
23 | asm volatile("nop" : : : "cr2" ); |
24 | if (i > 3) { |
25 | throw i; |
26 | } |
27 | srand(seed: i); |
28 | return rand() + i; |
29 | } |
30 | |
31 | void __attribute__((noinline)) test(int argc, const char **argv) { |
32 | int a = atoi(nptr: argv[1]); |
33 | int b = atoi(nptr: argv[2]); |
34 | try { |
35 | test2(i: a < b ? argc : b); |
36 | } catch (int num) { |
37 | assert(!(a < b)); |
38 | } |
39 | } |
40 | int main(int, char**) { |
41 | const char *av[]={"a.out" , "12" , "10" }; |
42 | test(argc: 4, argv: av); |
43 | return 0; |
44 | } |
45 | |