1 ; RUN: opt -safe-stack -S -mtriple=x86_64-unknown < %s -o - | FileCheck %s
2 ; RUN: opt -passes=safe-stack -S -mtriple=x86_64-unknown < %s -o - | FileCheck %s
4 define void @foo() safestack sspreq {
6 ; CHECK: %[[USP:.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
7 ; CHECK: %[[USST:.*]] = getelementptr i8, ptr %[[USP]], i32 -16
8 ; CHECK: store ptr %[[USST]], ptr @__safestack_unsafe_stack_ptr
10 ; CHECK: %[[A:.*]] = getelementptr i8, ptr %[[USP]], i32 -8
11 ; CHECK: %[[StackGuard:.*]] = call ptr @llvm.stackguard()
12 ; CHECK: store ptr %[[StackGuard]], ptr %[[A]]
13 %a = alloca i8, align 1
15 ; CHECK: call void @Capture
16 call void @Capture(ptr %a)
18 ; CHECK: %[[B:.*]] = load ptr, ptr %[[A]]
19 ; CHECK: %[[COND:.*]] = icmp ne ptr %[[StackGuard]], %[[B]]
20 ; CHECK: br i1 %[[COND]], {{.*}} !prof
22 ; CHECK: call void @__stack_chk_fail()
23 ; CHECK-NEXT: unreachable
25 ; CHECK: store ptr %[[USP]], ptr @__safestack_unsafe_stack_ptr
26 ; CHECK-NEXT: ret void
30 declare void @Capture(ptr)