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