Debian Codegraph @

llvm/test/Transforms/SafeStack/X86/array.ll

raw
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
3 ; RUN: opt -passes=safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
4 ; RUN: opt -passes=safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
5
6 ; array [4 x i8]
7 ; Requires protector.
8
9 ; CHECK: @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global ptr
10
11 define void @foo(ptr %a) nounwind uwtable safestack {
12 entry:
13 ; CHECK: %[[USP:.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
14
15 ; CHECK: %[[USST:.*]] = getelementptr i8, ptr %[[USP]], i32 -16
16
17 ; CHECK: store ptr %[[USST]], ptr @__safestack_unsafe_stack_ptr
18
19 %a.addr = alloca ptr, align 8
20 %buf = alloca [4 x i8], align 1
21
22 ; CHECK: %[[AADDR:.*]] = alloca ptr, align 8
23 ; CHECK: store ptr {{.*}}, ptr %[[AADDR]], align 8
24 store ptr %a, ptr %a.addr, align 8
25
26 ; CHECK: %[[A2:.*]] = load ptr, ptr %[[AADDR]], align 8
27 ; CHECK: %[[BUFPTR:.*]] = getelementptr i8, ptr %[[USP]], i32 -4
28 %a2 = load ptr, ptr %a.addr, align 8
29
30 ; CHECK: call ptr @strcpy(ptr %[[BUFPTR]], ptr %[[A2]])
31 %call = call ptr @strcpy(ptr %buf, ptr %a2)
32
33 ; CHECK: store ptr %[[USP]], ptr @__safestack_unsafe_stack_ptr
34 ret void
35 }
36
37 ; Load from an array at a fixed offset, no overflow.
38 define i8 @StaticArrayFixedSafe() nounwind uwtable safestack {
39 entry:
40 ; CHECK-LABEL: define i8 @StaticArrayFixedSafe(
41 ; CHECK-NOT: __safestack_unsafe_stack_ptr
42 ; CHECK: ret i8
43 %buf = alloca i8, i32 4, align 1
44 %gep = getelementptr inbounds i8, ptr %buf, i32 2
45 %x = load i8, ptr %gep, align 1
46 ret i8 %x
47 }
48
49 ; Load from an array at a fixed offset with overflow.
50 define i8 @StaticArrayFixedUnsafe() nounwind uwtable safestack {
51 entry:
52 ; CHECK-LABEL: define i8 @StaticArrayFixedUnsafe(
53 ; CHECK: __safestack_unsafe_stack_ptr
54 ; CHECK: ret i8
55 %buf = alloca i8, i32 4, align 1
56 %gep = getelementptr inbounds i8, ptr %buf, i32 5
57 %x = load i8, ptr %gep, align 1
58 ret i8 %x
59 }
60
61 ; Load from an array at an unknown offset.
62 define i8 @StaticArrayVariableUnsafe(i32 %ofs) nounwind uwtable safestack {
63 entry:
64 ; CHECK-LABEL: define i8 @StaticArrayVariableUnsafe(
65 ; CHECK: __safestack_unsafe_stack_ptr
66 ; CHECK: ret i8
67 %buf = alloca i8, i32 4, align 1
68 %gep = getelementptr inbounds i8, ptr %buf, i32 %ofs
69 %x = load i8, ptr %gep, align 1
70 ret i8 %x
71 }
72
73 ; Load from an array of an unknown size.
74 define i8 @DynamicArrayUnsafe(i32 %sz) nounwind uwtable safestack {
75 entry:
76 ; CHECK-LABEL: define i8 @DynamicArrayUnsafe(
77 ; CHECK: __safestack_unsafe_stack_ptr
78 ; CHECK: ret i8
79 %buf = alloca i8, i32 %sz, align 1
80 %gep = getelementptr inbounds i8, ptr %buf, i32 2
81 %x = load i8, ptr %gep, align 1
82 ret i8 %x
83 }
84
85 declare ptr @strcpy(ptr, ptr)