1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 // VE only supports SjLj and doesn't provide _Unwind_Backtrace.
12 // UNSUPPORTED: target={{ve-.*}}
18 extern "C" _Unwind_Reason_Code
19 trace_function(struct _Unwind_Context
*, void* ntraced
) {
20 (*reinterpret_cast<size_t*>(ntraced
))++;
21 // We should never have a call stack this deep...
22 assert(*reinterpret_cast<size_t*>(ntraced
) < 20);
23 return _URC_NO_REASON
;
26 __attribute__ ((__noinline__
))
27 void call3_throw(size_t* ntraced
) {
29 _Unwind_Backtrace(trace_function
, ntraced
);
35 __attribute__ ((__noinline__
, __disable_tail_calls__
))
36 void call3_nothrow(size_t* ntraced
) {
37 _Unwind_Backtrace(trace_function
, ntraced
);
40 __attribute__ ((__noinline__
, __disable_tail_calls__
))
41 void call2(size_t* ntraced
, bool do_throw
) {
45 call3_nothrow(ntraced
);
49 __attribute__ ((__noinline__
, __disable_tail_calls__
))
50 void call1(size_t* ntraced
, bool do_throw
) {
51 call2(ntraced
, do_throw
);
54 int main(int, char**) {
55 size_t throw_ntraced
= 0;
56 size_t nothrow_ntraced
= 0;
58 call1(¬hrow_ntraced
, false);
61 call1(&throw_ntraced
, true);
66 // Different platforms (and different runtimes) will unwind a different number
67 // of times, so we can't make any better assumptions than this.
68 assert(nothrow_ntraced
> 1);
69 assert(throw_ntraced
== nothrow_ntraced
); // Make sure we unwind through catch