xref: /aosp_15_r20/external/llvm/test/Instrumentation/AddressSanitizer/stack_layout.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; Test the ASan's stack layout.
2*9880d681SAndroid Build Coastguard Worker; More tests in tests/Transforms/Utils/ASanStackFrameLayoutTest.cpp
3*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -asan -asan-module -asan-stack-dynamic-alloca=0 -S \
4*9880d681SAndroid Build Coastguard Worker; RUN:     | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-STATIC
5*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -asan -asan-module -asan-stack-dynamic-alloca=1 -S \
6*9880d681SAndroid Build Coastguard Worker; RUN:     | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DYNAMIC
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Workertarget 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"
9*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu"
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Workerdeclare void @Use(i8*)
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker; CHECK: private unnamed_addr constant{{.*}}3 32 10 3 XXX 64 20 3 YYY 128 30 3 ZZZ
14*9880d681SAndroid Build Coastguard Worker; CHECK: private unnamed_addr constant{{.*}}3 32 5 3 AAA 64 55 3 BBB 160 555 3 CCC
15*9880d681SAndroid Build Coastguard Worker; CHECK: private unnamed_addr constant{{.*}}3 256 128 3 CCC 448 128 3 BBB 608 128 3 AAA
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Workerdefine void @Func1() sanitize_address {
18*9880d681SAndroid Build Coastguard Workerentry:
19*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: Func1
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker; CHECK-STATIC: alloca [192 x i8]
22*9880d681SAndroid Build Coastguard Worker; CHECK-DYNAMIC: alloca i8, i64 192
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
25*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
26*9880d681SAndroid Build Coastguard Worker  %XXX = alloca [10 x i8], align 1
27*9880d681SAndroid Build Coastguard Worker  %YYY = alloca [20 x i8], align 1
28*9880d681SAndroid Build Coastguard Worker  %ZZZ = alloca [30 x i8], align 1
29*9880d681SAndroid Build Coastguard Worker  %arr1.ptr = bitcast [10 x i8]* %XXX to i8*
30*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr1.ptr
31*9880d681SAndroid Build Coastguard Worker  %arr2.ptr = bitcast [20 x i8]* %YYY to i8*
32*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr2.ptr
33*9880d681SAndroid Build Coastguard Worker  %arr3.ptr = bitcast [30 x i8]* %ZZZ to i8*
34*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr3.ptr
35*9880d681SAndroid Build Coastguard Worker  ret void
36*9880d681SAndroid Build Coastguard Worker}
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workerdefine void @Func2() sanitize_address {
39*9880d681SAndroid Build Coastguard Workerentry:
40*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: Func2
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker; CHECK-STATIC: alloca [864 x i8]
43*9880d681SAndroid Build Coastguard Worker; CHECK-DYNAMIC: alloca i8, i64 864
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
46*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
47*9880d681SAndroid Build Coastguard Worker  %AAA = alloca [5 x i8], align 1
48*9880d681SAndroid Build Coastguard Worker  %BBB = alloca [55 x i8], align 1
49*9880d681SAndroid Build Coastguard Worker  %CCC = alloca [555 x i8], align 1
50*9880d681SAndroid Build Coastguard Worker  %arr1.ptr = bitcast [5 x i8]* %AAA to i8*
51*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr1.ptr
52*9880d681SAndroid Build Coastguard Worker  %arr2.ptr = bitcast [55 x i8]* %BBB to i8*
53*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr2.ptr
54*9880d681SAndroid Build Coastguard Worker  %arr3.ptr = bitcast [555 x i8]* %CCC to i8*
55*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr3.ptr
56*9880d681SAndroid Build Coastguard Worker  ret void
57*9880d681SAndroid Build Coastguard Worker}
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker; Check that we reorder vars according to alignment and handle large alignments.
60*9880d681SAndroid Build Coastguard Workerdefine void @Func3() sanitize_address {
61*9880d681SAndroid Build Coastguard Workerentry:
62*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: Func3
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker; CHECK-STATIC: alloca [768 x i8]
65*9880d681SAndroid Build Coastguard Worker; CHECK-DYNAMIC: alloca i8, i64 768
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
68*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
69*9880d681SAndroid Build Coastguard Worker  %AAA = alloca [128 x i8], align 16
70*9880d681SAndroid Build Coastguard Worker  %BBB = alloca [128 x i8], align 64
71*9880d681SAndroid Build Coastguard Worker  %CCC = alloca [128 x i8], align 256
72*9880d681SAndroid Build Coastguard Worker  %arr1.ptr = bitcast [128 x i8]* %AAA to i8*
73*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr1.ptr
74*9880d681SAndroid Build Coastguard Worker  %arr2.ptr = bitcast [128 x i8]* %BBB to i8*
75*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr2.ptr
76*9880d681SAndroid Build Coastguard Worker  %arr3.ptr = bitcast [128 x i8]* %CCC to i8*
77*9880d681SAndroid Build Coastguard Worker  store volatile i8 0, i8* %arr3.ptr
78*9880d681SAndroid Build Coastguard Worker  ret void
79*9880d681SAndroid Build Coastguard Worker}
80