xref: /llvm-project/llvm/test/Transforms/SafeStack/X86/layout-frag.ll (revision 3bd517205799a152689434ceddf9493765f1e883)
1; Test that safestack layout reuses a region w/o fragmentation.
2; RUN: opt -safe-stack -safe-stack-coloring=1 -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
3; RUN: opt -passes=safe-stack -safe-stack-coloring=1 -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
4
5define void @f() safestack {
6; CHECK-LABEL: define void @f
7entry:
8; CHECK:  %[[USP:.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
9; CHECK:   getelementptr i8, ptr %[[USP]], i32 -16
10
11  %x0 = alloca i64, align 8
12  %x1 = alloca i8, align 1
13  %x2 = alloca i64, align 8
14
15
16  call void @llvm.lifetime.start.p0(i64 8, ptr %x0)
17  call void @capture64(ptr %x0)
18  call void @llvm.lifetime.end.p0(i64 8, ptr %x0)
19
20  call void @llvm.lifetime.start.p0(i64 1, ptr %x1)
21  call void @llvm.lifetime.start.p0(i64 8, ptr %x2)
22  call void @capture8(ptr %x1)
23  call void @capture64(ptr %x2)
24  call void @llvm.lifetime.end.p0(i64 1, ptr %x1)
25  call void @llvm.lifetime.end.p0(i64 8, ptr %x2)
26
27; Test that i64 allocas share space.
28; CHECK: getelementptr i8, ptr %unsafe_stack_ptr, i32 -8
29; CHECK: getelementptr i8, ptr %unsafe_stack_ptr, i32 -9
30; CHECK: getelementptr i8, ptr %unsafe_stack_ptr, i32 -8
31
32  ret void
33}
34
35declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
36declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
37declare void @capture8(ptr)
38declare void @capture64(ptr)
39