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
15 extern "C" _Unwind_Reason_Code
16 trace_function(struct _Unwind_Context
*, void* ntraced
) {
17 (*reinterpret_cast<size_t*>(ntraced
))++;
18 // We should never have a call stack this deep...
19 assert(*reinterpret_cast<size_t*>(ntraced
) < 20);
20 return _URC_NO_REASON
;
23 __attribute__ ((__noinline__
))
24 void call3_throw(size_t* ntraced
) {
26 _Unwind_Backtrace(trace_function
, ntraced
);
32 __attribute__ ((__noinline__
, __disable_tail_calls__
))
33 void call3_nothrow(size_t* ntraced
) {
34 _Unwind_Backtrace(trace_function
, ntraced
);
37 __attribute__ ((__noinline__
, __disable_tail_calls__
))
38 void call2(size_t* ntraced
, bool do_throw
) {
42 call3_nothrow(ntraced
);
46 __attribute__ ((__noinline__
, __disable_tail_calls__
))
47 void call1(size_t* ntraced
, bool do_throw
) {
48 call2(ntraced
, do_throw
);
51 int main(int, char**) {
52 size_t throw_ntraced
= 0;
53 size_t nothrow_ntraced
= 0;
55 call1(¬hrow_ntraced
, false);
58 call1(&throw_ntraced
, true);
63 // Different platforms (and different runtimes) will unwind a different number
64 // of times, so we can't make any better assumptions than this.
65 assert(nothrow_ntraced
> 1);
66 assert(throw_ntraced
== nothrow_ntraced
); // Make sure we unwind through catch