1 ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
2 ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
7 ; CHECK: @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global ptr
9 define void @foo(ptr %a) nounwind uwtable safestack {
11 ; CHECK: %[[USP:.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
13 ; CHECK: %[[USST:.*]] = getelementptr i8, ptr %[[USP]], i32 -16
15 ; CHECK: store ptr %[[USST]], ptr @__safestack_unsafe_stack_ptr
17 %a.addr = alloca ptr, align 8
18 %buf = alloca [4 x i8], align 1
20 ; CHECK: %[[AADDR:.*]] = alloca ptr, align 8
21 ; CHECK: store ptr {{.*}}, ptr %[[AADDR]], align 8
22 store ptr %a, ptr %a.addr, align 8
24 ; CHECK: %[[A2:.*]] = load ptr, ptr %[[AADDR]], align 8
25 ; CHECK: %[[BUFPTR:.*]] = getelementptr i8, ptr %[[USP]], i32 -4
26 %a2 = load ptr, ptr %a.addr, align 8
28 ; CHECK: call ptr @strcpy(ptr %[[BUFPTR]], ptr %[[A2]])
29 %call = call ptr @strcpy(ptr %buf, ptr %a2)
31 ; CHECK: store ptr %[[USP]], ptr @__safestack_unsafe_stack_ptr
35 ; Load from an array at a fixed offset, no overflow.
36 define i8 @StaticArrayFixedSafe() nounwind uwtable safestack {
38 ; CHECK-LABEL: define i8 @StaticArrayFixedSafe(
39 ; CHECK-NOT: __safestack_unsafe_stack_ptr
41 %buf = alloca i8, i32 4, align 1
42 %gep = getelementptr inbounds i8, ptr %buf, i32 2
43 %x = load i8, ptr %gep, align 1
47 ; Load from an array at a fixed offset with overflow.
48 define i8 @StaticArrayFixedUnsafe() nounwind uwtable safestack {
50 ; CHECK-LABEL: define i8 @StaticArrayFixedUnsafe(
51 ; CHECK: __safestack_unsafe_stack_ptr
53 %buf = alloca i8, i32 4, align 1
54 %gep = getelementptr inbounds i8, ptr %buf, i32 5
55 %x = load i8, ptr %gep, align 1
59 ; Load from an array at an unknown offset.
60 define i8 @StaticArrayVariableUnsafe(i32 %ofs) nounwind uwtable safestack {
62 ; CHECK-LABEL: define i8 @StaticArrayVariableUnsafe(
63 ; CHECK: __safestack_unsafe_stack_ptr
65 %buf = alloca i8, i32 4, align 1
66 %gep = getelementptr inbounds i8, ptr %buf, i32 %ofs
67 %x = load i8, ptr %gep, align 1
71 ; Load from an array of an unknown size.
72 define i8 @DynamicArrayUnsafe(i32 %sz) nounwind uwtable safestack {
74 ; CHECK-LABEL: define i8 @DynamicArrayUnsafe(
75 ; CHECK: __safestack_unsafe_stack_ptr
77 %buf = alloca i8, i32 %sz, align 1
78 %gep = getelementptr inbounds i8, ptr %buf, i32 2
79 %x = load i8, ptr %gep, align 1
83 declare ptr @strcpy(ptr, ptr)