1 // RUN: %clangxx_tsan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
7 __attribute__((noinline
)) void throws_int() {
11 __attribute__((noinline
)) void callee_throws() {
15 fprintf(stderr
, "callee_throws caught exception\n");
19 __attribute__((noinline
)) void throws_catches_rethrows() {
23 fprintf(stderr
, "throws_catches_rethrows caught exception\n");
28 __attribute__((noinline
)) void callee_rethrows() {
30 throws_catches_rethrows();
32 fprintf(stderr
, "callee_rethrows caught exception\n");
36 __attribute__((noinline
)) void throws_and_catches() {
40 fprintf(stderr
, "throws_and_catches caught exception\n");
44 __attribute__((noinline
)) void nested_try() {
49 fprintf(stderr
, "nested_try inner block caught exception\n");
52 fprintf(stderr
, "nested_try outer block caught exception\n");
56 __attribute__((noinline
)) void nested_try2() {
61 fprintf(stderr
, "nested_try inner block caught exception\n");
64 fprintf(stderr
, "nested_try outer block caught exception\n");
68 class ClassWithDestructor
{
70 ClassWithDestructor() {
71 fprintf(stderr
, "ClassWithDestructor\n");
73 ~ClassWithDestructor() {
74 fprintf(stderr
, "~ClassWithDestructor\n");
78 __attribute__((noinline
)) void local_object_then_throw() {
79 ClassWithDestructor obj
;
83 __attribute__((noinline
)) void cpp_object_with_destructor() {
85 local_object_then_throw();
87 fprintf(stderr
, "cpp_object_with_destructor caught exception\n");
91 __attribute__((noinline
)) void recursive_call(long n
) {
93 recursive_call(n
- 1);
99 __attribute__((noinline
)) void multiframe_unwind() {
103 fprintf(stderr
, "multiframe_unwind caught exception\n");
107 __attribute__((noinline
)) void longjmp_unwind() {
111 fprintf(stderr
, "longjmp_unwind jumped\n");
118 fprintf(stderr
, "longjmp_unwind caught exception\n");
122 __attribute__((noinline
)) void recursive_call_longjmp(jmp_buf env
, long n
) {
124 recursive_call_longjmp(env
, n
- 1);
130 __attribute__((noinline
)) void longjmp_unwind_multiple_frames() {
134 fprintf(stderr
, "longjmp_unwind_multiple_frames jumped\n");
139 recursive_call_longjmp(env
, 5);
141 fprintf(stderr
, "longjmp_unwind_multiple_frames caught exception\n");
145 #define CHECK_SHADOW_STACK(val) \
146 fprintf(stderr, (val == __tsan_testonly_shadow_stack_current_size() \
148 : "Shadow stack leak!\n"));
150 int main(int argc
, const char * argv
[]) {
151 fprintf(stderr
, "Hello, World!\n");
152 unsigned long shadow_stack_size
= __tsan_testonly_shadow_stack_current_size();
154 throws_and_catches();
155 CHECK_SHADOW_STACK(shadow_stack_size
);
158 CHECK_SHADOW_STACK(shadow_stack_size
);
161 CHECK_SHADOW_STACK(shadow_stack_size
);
164 CHECK_SHADOW_STACK(shadow_stack_size
);
167 CHECK_SHADOW_STACK(shadow_stack_size
);
169 cpp_object_with_destructor();
170 CHECK_SHADOW_STACK(shadow_stack_size
);
173 CHECK_SHADOW_STACK(shadow_stack_size
);
176 CHECK_SHADOW_STACK(shadow_stack_size
);
178 longjmp_unwind_multiple_frames();
179 CHECK_SHADOW_STACK(shadow_stack_size
);
184 // CHECK: Hello, World!
185 // CHECK-NOT: Shadow stack leak