106 lines · plain
1; Test the ASan's stack layout.2; More tests in tests/Transforms/Utils/ASanStackFrameLayoutTest.cpp3; RUN: opt < %s -passes=asan -asan-use-stack-safety=0 -asan-stack-dynamic-alloca=0 -asan-use-after-scope -S | FileCheck %s --check-prefixes=CHECK,CHECK-STATIC4; RUN: opt < %s -passes=asan -asan-use-stack-safety=0 -asan-stack-dynamic-alloca=1 -asan-use-after-scope -S | FileCheck %s --check-prefixes=CHECK,CHECK-DYNAMIC5 6target 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"7target triple = "x86_64-unknown-linux-gnu"8 9declare void @Use(ptr)10declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind11declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind12 13; CHECK: private unnamed_addr constant{{.*}}3 32 10 3 XXX 64 20 3 YYY 128 30 3 ZZZ\014; CHECK: private unnamed_addr constant{{.*}}3 32 5 3 AAA 64 55 3 BBB 160 555 3 CCC\015; CHECK: private unnamed_addr constant{{.*}}3 256 128 3 CCC 448 128 3 BBB 608 128 3 AAA\016; CHECK: private unnamed_addr constant{{.*}}2 32 4 3 AAA 48 4 5 BBB:7\017 18define void @Func1() sanitize_address {19entry:20; CHECK-LABEL: Func121 22; CHECK-STATIC: alloca [192 x i8]23; CHECK-STATIC: %asan_local_stack_base = alloca i6424; CHECK-DYNAMIC: alloca i8, i64 19225 26; CHECK-NOT: alloca27; CHECK: ret void28 %XXX = alloca [10 x i8], align 129 %YYY = alloca [20 x i8], align 130 %ZZZ = alloca [30 x i8], align 131 store volatile i8 0, ptr %XXX32 store volatile i8 0, ptr %YYY33 store volatile i8 0, ptr %ZZZ34 ret void35}36 37define void @Func2() sanitize_address {38entry:39; CHECK-LABEL: Func240 41; CHECK-STATIC: alloca [864 x i8]42; CHECK-STATIC: %asan_local_stack_base = alloca i6443; CHECK-DYNAMIC: alloca i8, i64 86444 45; CHECK-NOT: alloca46; CHECK: ret void47 %AAA = alloca [5 x i8], align 148 %BBB = alloca [55 x i8], align 149 %CCC = alloca [555 x i8], align 150 store volatile i8 0, ptr %AAA51 store volatile i8 0, ptr %BBB52 store volatile i8 0, ptr %CCC53 ret void54}55 56; Check that we reorder vars according to alignment and handle large alignments.57define void @Func3() sanitize_address {58entry:59; CHECK-LABEL: Func360 61; CHECK-STATIC: alloca [768 x i8]62; CHECK-STATIC: %asan_local_stack_base = alloca i6463; CHECK-DYNAMIC: alloca i8, i64 76864 65; CHECK-NOT: alloca66; CHECK: ret void67 %AAA = alloca [128 x i8], align 1668 %BBB = alloca [128 x i8], align 6469 %CCC = alloca [128 x i8], align 25670 store volatile i8 0, ptr %AAA71 store volatile i8 0, ptr %BBB72 store volatile i8 0, ptr %CCC73 ret void74}75 76; Check that line numbers are attached to variable names if variable77; in the same file as a function.78define void @Func5() sanitize_address #0 !dbg !11 {79 %AAA = alloca i32, align 4 ; File is not the same as !1180 %BBB = alloca i32, align 4 ; File is the same as !1181 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %BBB), !dbg !1282 store volatile i32 5, ptr %BBB, align 483 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %AAA), !dbg !1484 store volatile i32 3, ptr %AAA, align 485 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %AAA), !dbg !1786 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %BBB), !dbg !1887 ret void88}89 90!llvm.dbg.cu = !{!0}91!llvm.module.flags = !{!3, !4}92!3 = !{i32 2, !"Dwarf Version", i32 4}93!4 = !{i32 2, !"Debug Info Version", i32 3}94 95!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)96!1 = !DIFile(filename: "../file1.c", directory: "/")97!11 = distinct !DISubprogram(name: "Func5", scope: !1, file: !1, line: 6, unit: !0)98!12 = !DILocation(line: 7, column: 3, scope: !11)99!18 = !DILocation(line: 10, column: 1, scope: !11)100 101!21 = !DIFile(filename: "../file2.c", directory: "/")102!6 = distinct !DISubprogram(name: "Func4", scope: !1, file: !21, line: 2, unit: !0)103!15 = distinct !DILocation(line: 8, column: 3, scope: !11)104!14 = !DILocation(line: 3, column: 3, scope: !6, inlinedAt: !15)105!17 = !DILocation(line: 4, column: 1, scope: !6, inlinedAt: !15)106