• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
4@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
5
6define void @bad_store() nounwind uwtable safestack {
7entry:
8  ; CHECK-LABEL: @bad_store(
9  ; CHECK: __safestack_unsafe_stack_ptr
10  ; CHECK: ret void
11  %a = alloca i32, align 4
12  %0 = ptrtoint i32* %a to i64
13  %1 = inttoptr i64 %0 to i64*
14  store i64 zeroinitializer, i64* %1
15  ret void
16}
17
18define void @good_store() nounwind uwtable safestack {
19entry:
20  ; CHECK-LABEL: @good_store(
21  ; CHECK-NOT: __safestack_unsafe_stack_ptr
22  ; CHECK: ret void
23  %a = alloca i32, align 4
24  %0 = bitcast i32* %a to i8*
25  store i8 zeroinitializer, i8* %0
26  ret void
27}
28
29define void @overflow_gep_store() nounwind uwtable safestack {
30entry:
31  ; CHECK-LABEL: @overflow_gep_store(
32  ; CHECK: __safestack_unsafe_stack_ptr
33  ; CHECK: ret void
34  %a = alloca i32, align 4
35  %0 = bitcast i32* %a to i8*
36  %1 = getelementptr i8, i8* %0, i32 4
37  store i8 zeroinitializer, i8* %1
38  ret void
39}
40
41define void @underflow_gep_store() nounwind uwtable safestack {
42entry:
43  ; CHECK-LABEL: @underflow_gep_store(
44  ; CHECK: __safestack_unsafe_stack_ptr
45  ; CHECK: ret void
46  %a = alloca i32, align 4
47  %0 = bitcast i32* %a to i8*
48  %1 = getelementptr i8, i8* %0, i32 -1
49  store i8 zeroinitializer, i8* %1
50  ret void
51}
52
53define void @good_gep_store() nounwind uwtable safestack {
54entry:
55  ; CHECK-LABEL: @good_gep_store(
56  ; CHECK-NOT: __safestack_unsafe_stack_ptr
57  ; CHECK: ret void
58  %a = alloca i32, align 4
59  %0 = bitcast i32* %a to i8*
60  %1 = getelementptr i8, i8* %0, i32 3
61  store i8 zeroinitializer, i8* %1
62  ret void
63}
64