summaryrefslogtreecommitdiff
path: root/test/Transforms/SafeStack/array.ll
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
commitdd58ef019b700900793a1eb48b52123db01b654e (patch)
treefcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /test/Transforms/SafeStack/array.ll
parent2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff)
Notes
Diffstat (limited to 'test/Transforms/SafeStack/array.ll')
-rw-r--r--test/Transforms/SafeStack/array.ll53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/Transforms/SafeStack/array.ll b/test/Transforms/SafeStack/array.ll
index 6036bfc2c9c5b..564213e6d58fa 100644
--- a/test/Transforms/SafeStack/array.ll
+++ b/test/Transforms/SafeStack/array.ll
@@ -1,9 +1,14 @@
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
+; RUN: opt -safe-stack -safe-stack-usp-storage=single-thread -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck -check-prefix=SINGLE-THREAD %s
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
+; RUN: opt -safe-stack -safe-stack-usp-storage=single-thread -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck -check-prefix=SINGLE-THREAD %s
; array [4 x i8]
; Requires protector.
+; CHECK: @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global i8*
+; SINGLE-THREAD: @__safestack_unsafe_stack_ptr = external global i8*
+
define void @foo(i8* %a) nounwind uwtable safestack {
entry:
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
@@ -35,4 +40,52 @@ entry:
ret void
}
+; Load from an array at a fixed offset, no overflow.
+define i8 @StaticArrayFixedSafe() nounwind uwtable safestack {
+entry:
+ ; CHECK-LABEL: define i8 @StaticArrayFixedSafe(
+ ; CHECK-NOT: __safestack_unsafe_stack_ptr
+ ; CHECK: ret i8
+ %buf = alloca i8, i32 4, align 1
+ %gep = getelementptr inbounds i8, i8* %buf, i32 2
+ %x = load i8, i8* %gep, align 1
+ ret i8 %x
+}
+
+; Load from an array at a fixed offset with overflow.
+define i8 @StaticArrayFixedUnsafe() nounwind uwtable safestack {
+entry:
+ ; CHECK-LABEL: define i8 @StaticArrayFixedUnsafe(
+ ; CHECK: __safestack_unsafe_stack_ptr
+ ; CHECK: ret i8
+ %buf = alloca i8, i32 4, align 1
+ %gep = getelementptr inbounds i8, i8* %buf, i32 5
+ %x = load i8, i8* %gep, align 1
+ ret i8 %x
+}
+
+; Load from an array at an unknown offset.
+define i8 @StaticArrayVariableUnsafe(i32 %ofs) nounwind uwtable safestack {
+entry:
+ ; CHECK-LABEL: define i8 @StaticArrayVariableUnsafe(
+ ; CHECK: __safestack_unsafe_stack_ptr
+ ; CHECK: ret i8
+ %buf = alloca i8, i32 4, align 1
+ %gep = getelementptr inbounds i8, i8* %buf, i32 %ofs
+ %x = load i8, i8* %gep, align 1
+ ret i8 %x
+}
+
+; Load from an array of an unknown size.
+define i8 @DynamicArrayUnsafe(i32 %sz) nounwind uwtable safestack {
+entry:
+ ; CHECK-LABEL: define i8 @DynamicArrayUnsafe(
+ ; CHECK: __safestack_unsafe_stack_ptr
+ ; CHECK: ret i8
+ %buf = alloca i8, i32 %sz, align 1
+ %gep = getelementptr inbounds i8, i8* %buf, i32 2
+ %x = load i8, i8* %gep, align 1
+ ret i8 %x
+}
+
declare i8* @strcpy(i8*, i8*)