[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / test / vendor / ibm / cond_reg_restore.pass.cpp
blob63817e1b13a25b8ea21518968c738489322bc152
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 //===----------------------------------------------------------------------===//
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.
13 // REQUIRES: target=powerpc{{(64)?}}-ibm-aix
14 // ADDITIONAL_COMPILE_FLAGS: -O3
15 // UNSUPPORTED: no-exceptions
17 #include <cstdlib>
18 #include <cassert>
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;
27 srand(i);
28 return rand() + i;
31 void __attribute__((noinline)) test(int argc, const char **argv) {
32 int a = atoi(argv[1]);
33 int b = atoi(argv[2]);
34 try {
35 test2(a < b ? argc : b);
36 } catch (int num) {
37 assert(!(a < b));
40 int main(int, char**) {
41 const char *av[]={"a.out", "12", "10"};
42 test(4, av);
43 return 0;