1 ; To test that safestack does not break the musttail call contract.
3 ; RUN: opt < %s --safe-stack -S | FileCheck %s
4 ; RUN: opt < %s -passes=safe-stack -S | FileCheck %s
6 target triple = "x86_64-unknown-linux-gnu"
8 declare i32 @foo(ptr %p)
9 declare void @alloca_test_use(ptr)
11 define i32 @call_foo(ptr %a) safestack {
12 ; CHECK-LABEL: @call_foo(
13 ; CHECK-NEXT: [[UNSAFE_STACK_PTR:%.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr, align 8
14 ; CHECK-NEXT: [[UNSAFE_STACK_STATIC_TOP:%.*]] = getelementptr i8, ptr [[UNSAFE_STACK_PTR]], i32 -16
15 ; CHECK-NEXT: store ptr [[UNSAFE_STACK_STATIC_TOP]], ptr @__safestack_unsafe_stack_ptr, align 8
16 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[UNSAFE_STACK_PTR]], i32 -10
17 ; CHECK-NEXT: call void @alloca_test_use(ptr [[TMP1]])
18 ; CHECK-NEXT: store ptr [[UNSAFE_STACK_PTR]], ptr @__safestack_unsafe_stack_ptr, align 8
19 ; CHECK-NEXT: [[R:%.*]] = musttail call i32 @foo(ptr [[A:%.*]])
20 ; CHECK-NEXT: ret i32 [[R]]
22 %x = alloca [10 x i8], align 1
23 call void @alloca_test_use(ptr %x)
24 %r = musttail call i32 @foo(ptr %a)
28 define i32 @call_foo_cast(ptr %a) safestack {
29 ; CHECK-LABEL: @call_foo_cast(
30 ; CHECK-NEXT: [[UNSAFE_STACK_PTR:%.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr, align 8
31 ; CHECK-NEXT: [[UNSAFE_STACK_STATIC_TOP:%.*]] = getelementptr i8, ptr [[UNSAFE_STACK_PTR]], i32 -16
32 ; CHECK-NEXT: store ptr [[UNSAFE_STACK_STATIC_TOP]], ptr @__safestack_unsafe_stack_ptr, align 8
33 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[UNSAFE_STACK_PTR]], i32 -10
34 ; CHECK-NEXT: call void @alloca_test_use(ptr [[TMP1]])
35 ; CHECK-NEXT: store ptr [[UNSAFE_STACK_PTR]], ptr @__safestack_unsafe_stack_ptr, align 8
36 ; CHECK-NEXT: [[R:%.*]] = musttail call i32 @foo(ptr [[A:%.*]])
37 ; CHECK-NEXT: [[T:%.*]] = bitcast i32 [[R]] to i32
38 ; CHECK-NEXT: ret i32 [[T]]
40 %x = alloca [10 x i8], align 1
41 call void @alloca_test_use(ptr %x)
42 %r = musttail call i32 @foo(ptr %a)
43 %t = bitcast i32 %r to i32