blob: 97e3bbb587238ea9e4a8bdecea205d73f656f5d9 [file] [log] [blame]
Kostya Serebryany4fb78012013-12-06 09:00:17 +00001; Test the ASan's stack layout.
2; More tests in tests/Transforms/Utils/ASanStackFrameLayoutTest.cpp
Alexey Samsonov4b7f4132014-12-11 21:53:03 +00003; RUN: opt < %s -asan -asan-module -asan-stack-dynamic-alloca=0 -S \
4; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-STATIC
5; RUN: opt < %s -asan -asan-module -asan-stack-dynamic-alloca=1 -S \
6; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DYNAMIC
Kostya Serebryany4fb78012013-12-06 09:00:17 +00007
8target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
11declare void @Use(i8*)
12
Alexander Potapenkocb66fe32013-12-25 17:06:04 +000013; CHECK: private unnamed_addr constant{{.*}}3 32 10 3 XXX 64 20 3 YYY 128 30 3 ZZZ
14; CHECK: private unnamed_addr constant{{.*}}3 32 5 3 AAA 64 55 3 BBB 160 555 3 CCC
15; CHECK: private unnamed_addr constant{{.*}}3 256 128 3 CCC 448 128 3 BBB 608 128 3 AAA
Kostya Serebryany4fb78012013-12-06 09:00:17 +000016
17define void @Func1() sanitize_address {
18entry:
19; CHECK-LABEL: Func1
Alexey Samsonov4b7f4132014-12-11 21:53:03 +000020
21; CHECK-STATIC: alloca [192 x i8]
22; CHECK-DYNAMIC: alloca i8, i64 192
23
Kostya Serebryany4fb78012013-12-06 09:00:17 +000024; CHECK-NOT: alloca
25; CHECK: ret void
26 %XXX = alloca [10 x i8], align 1
27 %YYY = alloca [20 x i8], align 1
28 %ZZZ = alloca [30 x i8], align 1
29 ret void
30}
31
32define void @Func2() sanitize_address {
33entry:
34; CHECK-LABEL: Func2
Alexey Samsonov4b7f4132014-12-11 21:53:03 +000035
36; CHECK-STATIC: alloca [864 x i8]
37; CHECK-DYNAMIC: alloca i8, i64 864
38
Kostya Serebryany4fb78012013-12-06 09:00:17 +000039; CHECK-NOT: alloca
40; CHECK: ret void
41 %AAA = alloca [5 x i8], align 1
42 %BBB = alloca [55 x i8], align 1
43 %CCC = alloca [555 x i8], align 1
44 ret void
45}
46
47; Check that we reorder vars according to alignment and handle large alignments.
48define void @Func3() sanitize_address {
49entry:
50; CHECK-LABEL: Func3
Alexey Samsonov4b7f4132014-12-11 21:53:03 +000051
52; CHECK-STATIC: alloca [768 x i8]
53; CHECK-DYNAMIC: alloca i8, i64 768
54
Kostya Serebryany4fb78012013-12-06 09:00:17 +000055; CHECK-NOT: alloca
56; CHECK: ret void
57 %AAA = alloca [128 x i8], align 16
58 %BBB = alloca [128 x i8], align 64
59 %CCC = alloca [128 x i8], align 256
60 ret void
61}