aboutsummaryrefslogtreecommitdiffstats
path: root/test/Instrumentation/AddressSanitizer
diff options
context:
space:
mode:
Diffstat (limited to 'test/Instrumentation/AddressSanitizer')
-rw-r--r--test/Instrumentation/AddressSanitizer/X86/asm_mov.ll123
-rw-r--r--test/Instrumentation/AddressSanitizer/X86/asm_mov.s76
-rw-r--r--test/Instrumentation/AddressSanitizer/X86/asm_mov_no_instrumentation.s44
-rw-r--r--test/Instrumentation/AddressSanitizer/X86/bug_11395.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/basic.ll21
-rw-r--r--test/Instrumentation/AddressSanitizer/coverage.ll35
-rw-r--r--test/Instrumentation/AddressSanitizer/different_scale_and_offset.ll41
-rw-r--r--test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll6
-rw-r--r--test/Instrumentation/AddressSanitizer/do-not-instrument-llvm-metadata.ll12
-rw-r--r--test/Instrumentation/AddressSanitizer/do-not-touch-odr-global.ll11
-rw-r--r--test/Instrumentation/AddressSanitizer/do-not-touch-threadlocal.ll4
-rw-r--r--test/Instrumentation/AddressSanitizer/freebsd.ll29
-rw-r--r--test/Instrumentation/AddressSanitizer/instrument-no-return.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/instrument_global.ll1
-rw-r--r--test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll4
-rw-r--r--test/Instrumentation/AddressSanitizer/keep-instrumented_functions.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/lifetime-uar.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/lifetime.ll2
-rw-r--r--test/Instrumentation/AddressSanitizer/stack-poisoning.ll43
-rw-r--r--test/Instrumentation/AddressSanitizer/stack_layout.ll49
-rw-r--r--test/Instrumentation/AddressSanitizer/test64.ll8
22 files changed, 429 insertions, 90 deletions
diff --git a/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll b/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll
new file mode 100644
index 0000000..7af8139
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll
@@ -0,0 +1,123 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+sse2 -asan-instrument-inline-assembly | FileCheck %s
+
+target 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"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: mov1b
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_load1@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_store1@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: movb {{.*}}, {{.*}}
+define void @mov1b(i8* %dst, i8* %src) #0 {
+entry:
+ tail call void asm sideeffect "movb ($1), %al \0A\09movb %al, ($0) \0A\09", "r,r,~{memory},~{rax},~{dirflag},~{fpsr},~{flags}"(i8* %dst, i8* %src) #1, !srcloc !0
+ ret void
+}
+
+; CHECK-LABEL: mov2b
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_load2@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_store2@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: movw {{.*}}, {{.*}}
+define void @mov2b(i16* %dst, i16* %src) #0 {
+entry:
+ tail call void asm sideeffect "movw ($1), %ax \0A\09movw %ax, ($0) \0A\09", "r,r,~{memory},~{rax},~{dirflag},~{fpsr},~{flags}"(i16* %dst, i16* %src) #1, !srcloc !1
+ ret void
+}
+
+; CHECK-LABEL: mov4b
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_load4@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_store4@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: movl {{.*}}, {{.*}}
+define void @mov4b(i32* %dst, i32* %src) #0 {
+entry:
+ tail call void asm sideeffect "movl ($1), %eax \0A\09movl %eax, ($0) \0A\09", "r,r,~{memory},~{rax},~{dirflag},~{fpsr},~{flags}"(i32* %dst, i32* %src) #1, !srcloc !2
+ ret void
+}
+
+; CHECK-LABEL: mov8b
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_load8@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_store8@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: movq {{.*}}, {{.*}}
+define void @mov8b(i64* %dst, i64* %src) #0 {
+entry:
+ tail call void asm sideeffect "movq ($1), %rax \0A\09movq %rax, ($0) \0A\09", "r,r,~{memory},~{rax},~{dirflag},~{fpsr},~{flags}"(i64* %dst, i64* %src) #1, !srcloc !3
+ ret void
+}
+
+; CHECK-LABEL: mov16b
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_load16@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: subq $128, %rsp
+; CHECK-NEXT: pushq %rdi
+; CHECK-NEXT: leaq {{.*}}, %rdi
+; CHECK-NEXT: callq __sanitizer_sanitize_store16@PLT
+; CHECK-NEXT: popq %rdi
+; CHECK-NEXT: addq $128, %rsp
+
+; CHECK: movaps {{.*}}, {{.*}}
+define void @mov16b(<2 x i64>* %dst, <2 x i64>* %src) #0 {
+entry:
+ tail call void asm sideeffect "movaps ($1), %xmm0 \0A\09movaps %xmm0, ($0) \0A\09", "r,r,~{memory},~{xmm0},~{dirflag},~{fpsr},~{flags}"(<2 x i64>* %dst, <2 x i64>* %src) #1, !srcloc !4
+ ret void
+}
+
+attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind }
+
+!0 = metadata !{i32 98, i32 122, i32 160}
+!1 = metadata !{i32 305, i32 329, i32 367}
+!2 = metadata !{i32 512, i32 537, i32 576}
+!3 = metadata !{i32 721, i32 746, i32 785}
+!4 = metadata !{i32 929, i32 957, i32 999}
diff --git a/test/Instrumentation/AddressSanitizer/X86/asm_mov.s b/test/Instrumentation/AddressSanitizer/X86/asm_mov.s
new file mode 100644
index 0000000..9001067
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/X86/asm_mov.s
@@ -0,0 +1,76 @@
+# RUN: llvm-mc %s -triple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+sse2 -asan-instrument-inline-assembly | FileCheck %s
+
+ .text
+ .globl mov1b
+ .align 16, 0x90
+ .type mov1b,@function
+# CHECK-LABEL: mov1b:
+#
+# CHECK: subq $128, %rsp
+# CHECK-NEXT: pushq %rdi
+# CHECK-NEXT: leaq (%rsi), %rdi
+# CHECK-NEXT: callq __sanitizer_sanitize_load1@PLT
+# CHECK-NEXT: popq %rdi
+# CHECK-NEXT: addq $128, %rsp
+#
+# CHECK-NEXT: movb (%rsi), %al
+#
+# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: pushq %rdi
+# CHECK-NEXT: leaq (%rdi), %rdi
+# CHECK-NEXT: callq __sanitizer_sanitize_store1@PLT
+# CHECK-NEXT: popq %rdi
+# CHECK-NEXT: addq $128, %rsp
+#
+# CHECK-NEXT: movb %al, (%rdi)
+mov1b: # @mov1b
+ .cfi_startproc
+# BB#0:
+ #APP
+ movb (%rsi), %al
+ movb %al, (%rdi)
+
+ #NO_APP
+ retq
+.Ltmp0:
+ .size mov1b, .Ltmp0-mov1b
+ .cfi_endproc
+
+ .globl mov16b
+ .align 16, 0x90
+ .type mov16b,@function
+# CHECK-LABEL: mov16b:
+#
+# CHECK: subq $128, %rsp
+# CHECK-NEXT: pushq %rdi
+# CHECK-NEXT: leaq (%rsi), %rdi
+# CHECK-NEXT: callq __sanitizer_sanitize_load16@PLT
+# CHECK-NEXT: popq %rdi
+# CHECK-NEXT: addq $128, %rsp
+#
+# CHECK-NEXT: movaps (%rsi), %xmm0
+#
+# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: pushq %rdi
+# CHECK-NEXT: leaq (%rdi), %rdi
+# CHECK-NEXT: callq __sanitizer_sanitize_store16@PLT
+# CHECK-NEXT: popq %rdi
+# CHECK-NEXT: addq $128, %rsp
+#
+# CHECK-NEXT: movaps %xmm0, (%rdi)
+mov16b: # @mov16b
+ .cfi_startproc
+# BB#0:
+ #APP
+ movaps (%rsi), %xmm0
+ movaps %xmm0, (%rdi)
+
+ #NO_APP
+ retq
+.Ltmp1:
+ .size mov16b, .Ltmp1-mov16b
+ .cfi_endproc
+
+
+ .ident "clang version 3.5 "
+ .section ".note.GNU-stack","",@progbits
diff --git a/test/Instrumentation/AddressSanitizer/X86/asm_mov_no_instrumentation.s b/test/Instrumentation/AddressSanitizer/X86/asm_mov_no_instrumentation.s
new file mode 100644
index 0000000..a9ef4df
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/X86/asm_mov_no_instrumentation.s
@@ -0,0 +1,44 @@
+# RUN: llvm-mc %s -triple=x86_64-unknown-linux-gnu -mcpu=corei7 -mattr=+sse2 | FileCheck %s
+
+ .text
+ .globl mov1b
+ .align 16, 0x90
+ .type mov1b,@function
+# CHECK-LABEL: mov1b
+# CHECK-NOT: callq __sanitizer_sanitize_load1@PLT
+# CHECK-NOT: callq __sanitizer_sanitize_store1@PLT
+mov1b: # @mov1b
+ .cfi_startproc
+# BB#0:
+ #APP
+ movb (%rsi), %al
+ movb %al, (%rdi)
+
+ #NO_APP
+ retq
+.Ltmp0:
+ .size mov1b, .Ltmp0-mov1b
+ .cfi_endproc
+
+ .globl mov16b
+ .align 16, 0x90
+ .type mov16b,@function
+# CHECK-LABEL: mov16b
+# CHECK-NOT: callq __sanitizer_sanitize_load16@PLT
+# CHECK-NOT: callq __sanitizer_sanitize_store16@PLT
+mov16b: # @mov16b
+ .cfi_startproc
+# BB#0:
+ #APP
+ movaps (%rsi), %xmm0
+ movaps %xmm0, (%rdi)
+
+ #NO_APP
+ retq
+.Ltmp1:
+ .size mov16b, .Ltmp1-mov16b
+ .cfi_endproc
+
+
+ .ident "clang version 3.5 "
+ .section ".note.GNU-stack","",@progbits
diff --git a/test/Instrumentation/AddressSanitizer/X86/bug_11395.ll b/test/Instrumentation/AddressSanitizer/X86/bug_11395.ll
index 2c4d82e..63477aa 100644
--- a/test/Instrumentation/AddressSanitizer/X86/bug_11395.ll
+++ b/test/Instrumentation/AddressSanitizer/X86/bug_11395.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -asan -S | llc -o /dev/null
+; RUN: opt < %s -asan -asan-module -S | llc -o /dev/null
; The bug manifests as a reg alloc failure:
; error: ran out of registers during register allocation
; ModuleID = 'z.o'
diff --git a/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll b/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll
index 1087c9a..75adf40 100644
--- a/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll
+++ b/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -basicaa -gvn -asan -S | FileCheck %s
+; RUN: opt < %s -basicaa -gvn -asan -asan-module -S | FileCheck %s
; ASAN conflicts with load widening iff the widened load accesses data out of bounds
; (while the original unwidened loads do not).
; http://code.google.com/p/address-sanitizer/issues/detail?id=20#c1
diff --git a/test/Instrumentation/AddressSanitizer/basic.ll b/test/Instrumentation/AddressSanitizer/basic.ll
index 6002b9e..4863a3d 100644
--- a/test/Instrumentation/AddressSanitizer/basic.ll
+++ b/test/Instrumentation/AddressSanitizer/basic.ll
@@ -1,6 +1,6 @@
; Test basic address sanitizer instrumentation.
;
-; RUN: opt < %s -asan -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
@@ -89,25 +89,6 @@ entry:
; CHECK-NOT: = alloca
; CHECK: ret void
-; Check that asan does not touch allocas with alignment > 32.
-define void @alloca_alignment_test() sanitize_address {
-entry:
- %x = alloca [10 x i8], align 64
- %y = alloca [10 x i8], align 128
- %z = alloca [10 x i8], align 256
- call void @alloca_test_use([10 x i8]* %x)
- call void @alloca_test_use([10 x i8]* %y)
- call void @alloca_test_use([10 x i8]* %z)
- ret void
-}
-
-; CHECK: define void @alloca_alignment_test()
-; CHECK: = alloca{{.*}} align 64
-; CHECK: = alloca{{.*}} align 128
-; CHECK: = alloca{{.*}} align 256
-; CHECK: ret void
-
-
define void @LongDoubleTest(x86_fp80* nocapture %a) nounwind uwtable sanitize_address {
entry:
store x86_fp80 0xK3FFF8000000000000000, x86_fp80* %a, align 16
diff --git a/test/Instrumentation/AddressSanitizer/coverage.ll b/test/Instrumentation/AddressSanitizer/coverage.ll
index 47a54c0..0670132 100644
--- a/test/Instrumentation/AddressSanitizer/coverage.ll
+++ b/test/Instrumentation/AddressSanitizer/coverage.ll
@@ -1,13 +1,30 @@
-; RUN: opt < %s -asan -asan-coverage=1 -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -asan-coverage=1 -S | FileCheck %s --check-prefix=CHECK1
+; RUN: opt < %s -asan -asan-module -asan-coverage=2 -S | FileCheck %s --check-prefix=CHECK2
target 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"
target triple = "x86_64-unknown-linux-gnu"
-define i32 @foo(i32* %a) sanitize_address {
+define void @foo(i32* %a) sanitize_address {
entry:
- ret i32 0
+ %tobool = icmp eq i32* %a, null
+ br i1 %tobool, label %if.end, label %if.then
+
+ if.then: ; preds = %entry
+ store i32 0, i32* %a, align 4
+ br label %if.end
+
+ if.end: ; preds = %entry, %if.then
+ ret void
}
-; CHECK: define i32 @foo(i32* %a) #0 {
-; CHECK: %0 = load atomic i8* @__asan_gen_cov_foo monotonic, align 1
-; CHECK: %1 = icmp eq i8 0, %0
-; CHECK: br i1 %1, label %2, label %3
-; CHECK: call void @__sanitizer_cov(i64 ptrtoint (i32 (i32*)* @foo to i64))
-; CHECK: store atomic i8 1, i8* @__asan_gen_cov_foo monotonic, align 1
+; CHECK1-LABEL: define void @foo
+; CHECK1: %0 = load atomic i8* @__asan_gen_cov_foo monotonic, align 1
+; CHECK1: %1 = icmp eq i8 0, %0
+; CHECK1: br i1 %1, label %2, label %3
+; CHECK1: call void @__sanitizer_cov
+; CHECK1-NOT: call void @__sanitizer_cov
+; CHECK1: store atomic i8 1, i8* @__asan_gen_cov_foo monotonic, align 1
+
+; CHECK2-LABEL: define void @foo
+; CHECK2: call void @__sanitizer_cov
+; CHECK2: call void @__sanitizer_cov
+; CHECK2: call void @__sanitizer_cov
+; CHECK2-NOT: call void @__sanitizer_cov
+; CHECK2: ret void
diff --git a/test/Instrumentation/AddressSanitizer/different_scale_and_offset.ll b/test/Instrumentation/AddressSanitizer/different_scale_and_offset.ll
deleted file mode 100644
index b037176..0000000
--- a/test/Instrumentation/AddressSanitizer/different_scale_and_offset.ll
+++ /dev/null
@@ -1,41 +0,0 @@
-; Test non-default shadow mapping scale and offset.
-;
-; RUN: opt < %s -asan -asan-mapping-scale=2 -asan-mapping-offset-log=0 -S | FileCheck %s
-
-target 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"
-target triple = "x86_64-unknown-linux-gnu"
-
-; Test that ASan tells scale and offset to runtime.
-; CHECK: @__asan_mapping_offset = linkonce_odr constant i64 0
-; CHECK: @__asan_mapping_scale = linkonce_odr constant i64 2
-
-define i32 @test_load(i32* %a) sanitize_address {
-; CHECK: @test_load
-; CHECK-NOT: load
-; CHECK: %[[LOAD_ADDR:[^ ]*]] = ptrtoint i32* %a to i64
-; CHECK: lshr i64 %[[LOAD_ADDR]], 2
-
-; No need in shift for zero offset.
-; CHECK-NOT: or i64
-
-; CHECK: %[[LOAD_SHADOW_PTR:[^ ]*]] = inttoptr
-; CHECK: %[[LOAD_SHADOW:[^ ]*]] = load i8* %[[LOAD_SHADOW_PTR]]
-; CHECK: icmp ne i8
-; CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
-
-; No need in slow path for i32 and mapping scale equal to 2.
-; CHECK-NOT: and i64 %[[LOAD_ADDR]]
-;
-; The crash block reports the error.
-; CHECK: call void @__asan_report_load4(i64 %[[LOAD_ADDR]])
-; CHECK: unreachable
-;
-; The actual load.
-; CHECK: %tmp1 = load i32* %a
-; CHECK: ret i32 %tmp1
-
-entry:
- %tmp1 = load i32* %a
- ret i32 %tmp1
-}
-
diff --git a/test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll b/test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll
index d4fd93c..cff83ab 100644
--- a/test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll
+++ b/test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll
@@ -1,6 +1,6 @@
; This test checks that we are not instrumenting globals
; that we created ourselves.
-; RUN: opt < %s -asan -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
@@ -16,5 +16,5 @@ declare void @_Z3fooPi(i32*)
; We create one global string constant for the stack frame above.
; It should have unnamed_addr and align 1.
; Make sure we don't create any other global constants.
-; CHECK: = internal unnamed_addr constant{{.*}}align 1
-; CHECK-NOT: = internal unnamed_addr constant
+; CHECK: = private unnamed_addr constant{{.*}}align 1
+; CHECK-NOT: = private unnamed_addr constant
diff --git a/test/Instrumentation/AddressSanitizer/do-not-instrument-llvm-metadata.ll b/test/Instrumentation/AddressSanitizer/do-not-instrument-llvm-metadata.ll
new file mode 100644
index 0000000..fbfc096
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/do-not-instrument-llvm-metadata.ll
@@ -0,0 +1,12 @@
+; This test checks that we are not instrumenting globals in llvm.metadata.
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@.str_noinst = private unnamed_addr constant [4 x i8] c"aaa\00", section "llvm.metadata"
+@.str_inst = private unnamed_addr constant [4 x i8] c"aaa\00",
+
+; CHECK-NOT: {{asan_gen.*str_noinst}}
+; CHECK: {{asan_gen.*str_inst}}
+; CHECK: @asan.module_ctor
diff --git a/test/Instrumentation/AddressSanitizer/do-not-touch-odr-global.ll b/test/Instrumentation/AddressSanitizer/do-not-touch-odr-global.ll
index 1687877..9775261 100644
--- a/test/Instrumentation/AddressSanitizer/do-not-touch-odr-global.ll
+++ b/test/Instrumentation/AddressSanitizer/do-not-touch-odr-global.ll
@@ -1,6 +1,11 @@
-; RUN: opt < %s -asan -S | FileCheck %s
+; This test checks that we instrument regular globals, but do not touch
+; the linkonce_odr ones.
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
; no action should be taken for these globals
-@v1 = linkonce_odr constant i8 1
-; CHECK-NOT: __asan_register_globals
+@global_noinst = linkonce_odr constant [2 x i8] [i8 1, i8 2]
+@global_inst = private constant [2 x i8] [i8 1, i8 2]
+; CHECK-NOT: {{asan_gen.*global_noinst}}
+; CHECK: {{asan_gen.*global_inst}}
+; CHECK: @asan.module_ctor
diff --git a/test/Instrumentation/AddressSanitizer/do-not-touch-threadlocal.ll b/test/Instrumentation/AddressSanitizer/do-not-touch-threadlocal.ll
index 89644d4..f863f44 100644
--- a/test/Instrumentation/AddressSanitizer/do-not-touch-threadlocal.ll
+++ b/test/Instrumentation/AddressSanitizer/do-not-touch-threadlocal.ll
@@ -1,6 +1,6 @@
-; RUN: opt < %s -asan -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
; no action should be taken for thread locals
@xxx = thread_local global i32 0, align 4
-; CHECK-NOT: __asan_register_globals
+; CHECK-NOT: {{call.*__asan_register_globals}}
diff --git a/test/Instrumentation/AddressSanitizer/freebsd.ll b/test/Instrumentation/AddressSanitizer/freebsd.ll
new file mode 100644
index 0000000..359529f
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/freebsd.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -asan -asan-module -S \
+; RUN: -mtriple=i386-unknown-freebsd \
+; RUN: -default-data-layout="e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" | \
+; RUN: FileCheck --check-prefix=CHECK-32 %s
+
+; RUN: opt < %s -asan -asan-module -S \
+; RUN: -mtriple=x86_64-unknown-freebsd \
+; RUN: -default-data-layout="e-m:e-i64:64-f80:128-n8:16:32:64-S128" | \
+; RUN: FileCheck --check-prefix=CHECK-64 %s
+
+define i32 @read_4_bytes(i32* %a) sanitize_address {
+entry:
+ %tmp1 = load i32* %a, align 4
+ ret i32 %tmp1
+}
+
+; CHECK-32: @read_4_bytes
+; CHECK-32-NOT: ret
+; Check for ASAN's Offset for 32-bit (2^30 or 0x40000000)
+; CHECK-32: lshr {{.*}} 3
+; CHECK-32-NEXT: {{1073741824}}
+; CHECK-32: ret
+
+; CHECK-64: @read_4_bytes
+; CHECK-64-NOT: ret
+; Check for ASAN's Offset for 64-bit (2^46 or 0x400000000000)
+; CHECK-64: lshr {{.*}} 3
+; CHECK-64-NEXT: {{70368744177664}}
+; CHECK-64: ret
diff --git a/test/Instrumentation/AddressSanitizer/instrument-no-return.ll b/test/Instrumentation/AddressSanitizer/instrument-no-return.ll
index 2d835a3..5d5c592 100644
--- a/test/Instrumentation/AddressSanitizer/instrument-no-return.ll
+++ b/test/Instrumentation/AddressSanitizer/instrument-no-return.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -asan -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
; AddressSanitizer must insert __asan_handle_no_return
; before every noreturn call or invoke.
diff --git a/test/Instrumentation/AddressSanitizer/instrument_global.ll b/test/Instrumentation/AddressSanitizer/instrument_global.ll
index 4717277..7945e81 100644
--- a/test/Instrumentation/AddressSanitizer/instrument_global.ll
+++ b/test/Instrumentation/AddressSanitizer/instrument_global.ll
@@ -7,6 +7,7 @@ target triple = "x86_64-unknown-linux-gnu"
; module ctor/dtor
; CHECK: llvm.global_ctors
+; CHECK: @__asan_gen_ = private constant [8 x i8] c"<stdin>\00", align 1
; CHECK: llvm.global_dtors
; Test that we don't instrument global arrays with static initializer
diff --git a/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll b/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll
index 23cf6d2..195785f 100644
--- a/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll
+++ b/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll
@@ -1,6 +1,6 @@
; Test that AddressSanitizer instruments "(*a)++" only once.
-; RUN: opt < %s -asan -S -asan-opt=1 | FileCheck %s -check-prefix=OPT1
-; RUN: opt < %s -asan -S -asan-opt=0 | FileCheck %s -check-prefix=OPT0
+; RUN: opt < %s -asan -asan-module -S -asan-opt=1 | FileCheck %s -check-prefix=OPT1
+; RUN: opt < %s -asan -asan-module -S -asan-opt=0 | FileCheck %s -check-prefix=OPT0
target 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"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/test/Instrumentation/AddressSanitizer/keep-instrumented_functions.ll b/test/Instrumentation/AddressSanitizer/keep-instrumented_functions.ll
index ff3bbb0..8726b8e 100644
--- a/test/Instrumentation/AddressSanitizer/keep-instrumented_functions.ll
+++ b/test/Instrumentation/AddressSanitizer/keep-instrumented_functions.ll
@@ -1,5 +1,5 @@
; Test the -asan-keep-uninstrumented-functions flag: FOO should get cloned
-; RUN: opt < %s -asan -asan-keep-uninstrumented-functions -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -asan-keep-uninstrumented-functions -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/test/Instrumentation/AddressSanitizer/lifetime-uar.ll b/test/Instrumentation/AddressSanitizer/lifetime-uar.ll
index 21eaf7f..25577de 100644
--- a/test/Instrumentation/AddressSanitizer/lifetime-uar.ll
+++ b/test/Instrumentation/AddressSanitizer/lifetime-uar.ll
@@ -1,5 +1,5 @@
; Test handling of llvm.lifetime intrinsics in UAR mode.
-; RUN: opt < %s -asan -asan-use-after-return -asan-check-lifetime -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -asan-use-after-return -asan-check-lifetime -S | FileCheck %s
target 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"
diff --git a/test/Instrumentation/AddressSanitizer/lifetime.ll b/test/Instrumentation/AddressSanitizer/lifetime.ll
index d80331e..1961997 100644
--- a/test/Instrumentation/AddressSanitizer/lifetime.ll
+++ b/test/Instrumentation/AddressSanitizer/lifetime.ll
@@ -1,5 +1,5 @@
; Test hanlding of llvm.lifetime intrinsics.
-; RUN: opt < %s -asan -asan-check-lifetime -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -asan-check-lifetime -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/test/Instrumentation/AddressSanitizer/stack-poisoning.ll b/test/Instrumentation/AddressSanitizer/stack-poisoning.ll
new file mode 100644
index 0000000..6919e53
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/stack-poisoning.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -asan -asan-module -asan-use-after-return -S | FileCheck --check-prefix=CHECK-UAR %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck --check-prefix=CHECK-PLAIN %s
+target datalayout = "e-i64:64-f80:128-s:64-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @Foo(i8*)
+
+define void @Bar() uwtable sanitize_address {
+entry:
+; CHECK-PLAIN-LABEL: Bar
+; CHECK-PLAIN-NOT: label
+; CHECK-PLAIN: ret void
+
+; CHECK-UAR-LABEL: Bar
+; CHECK-UAR: load i32* @__asan_option_detect_stack_use_after_return
+; CHECK-UAR: label
+; CHECK-UAR: call i64 @__asan_stack_malloc_1
+; CHECK-UAR: label
+; CHECK-UAR: call void @Foo
+; If LocalStackBase != OrigStackBase
+; CHECK-UAR: label
+; Then Block: poison the entire frame.
+ ; CHECK-UAR: store i64 -723401728380766731
+ ; CHECK-UAR: store i64 -723401728380766731
+ ; CHECK-UAR: store i8 0
+ ; CHECK-UAR-NOT: store
+ ; CHECK-UAR: label
+; Else Block: no UAR frame. Only unpoison the redzones.
+ ; CHECK-UAR: store i64 0
+ ; CHECK-UAR: store i32 0
+ ; CHECK-UAR-NOT: store
+ ; CHECK-UAR: label
+; Done, no more stores.
+; CHECK-UAR-NOT: store
+; CHECK-UAR: ret void
+
+ %x = alloca [20 x i8], align 16
+ %arraydecay = getelementptr inbounds [20 x i8]* %x, i64 0, i64 0
+ call void @Foo(i8* %arraydecay)
+ ret void
+}
+
+
diff --git a/test/Instrumentation/AddressSanitizer/stack_layout.ll b/test/Instrumentation/AddressSanitizer/stack_layout.ll
new file mode 100644
index 0000000..c027acf
--- /dev/null
+++ b/test/Instrumentation/AddressSanitizer/stack_layout.ll
@@ -0,0 +1,49 @@
+; Test the ASan's stack layout.
+; More tests in tests/Transforms/Utils/ASanStackFrameLayoutTest.cpp
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
+
+target 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"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @Use(i8*)
+
+; CHECK: private unnamed_addr constant{{.*}}3 32 10 3 XXX 64 20 3 YYY 128 30 3 ZZZ
+; CHECK: private unnamed_addr constant{{.*}}3 32 5 3 AAA 64 55 3 BBB 160 555 3 CCC
+; CHECK: private unnamed_addr constant{{.*}}3 256 128 3 CCC 448 128 3 BBB 608 128 3 AAA
+
+define void @Func1() sanitize_address {
+entry:
+; CHECK-LABEL: Func1
+; CHECK: alloca [192 x i8]
+; CHECK-NOT: alloca
+; CHECK: ret void
+ %XXX = alloca [10 x i8], align 1
+ %YYY = alloca [20 x i8], align 1
+ %ZZZ = alloca [30 x i8], align 1
+ ret void
+}
+
+define void @Func2() sanitize_address {
+entry:
+; CHECK-LABEL: Func2
+; CHECK: alloca [864 x i8]
+; CHECK-NOT: alloca
+; CHECK: ret void
+ %AAA = alloca [5 x i8], align 1
+ %BBB = alloca [55 x i8], align 1
+ %CCC = alloca [555 x i8], align 1
+ ret void
+}
+
+; Check that we reorder vars according to alignment and handle large alignments.
+define void @Func3() sanitize_address {
+entry:
+; CHECK-LABEL: Func3
+; CHECK: alloca [768 x i8]
+; CHECK-NOT: alloca
+; CHECK: ret void
+ %AAA = alloca [128 x i8], align 16
+ %BBB = alloca [128 x i8], align 64
+ %CCC = alloca [128 x i8], align 256
+ ret void
+}
diff --git a/test/Instrumentation/AddressSanitizer/test64.ll b/test/Instrumentation/AddressSanitizer/test64.ll
index 6aa5c28..4f3ed5b 100644
--- a/test/Instrumentation/AddressSanitizer/test64.ll
+++ b/test/Instrumentation/AddressSanitizer/test64.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -asan -S | FileCheck %s
+; RUN: opt < %s -asan -asan-module -S | FileCheck %s
target 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"
target triple = "x86_64-unknown-linux-gnu"
define i32 @read_4_bytes(i32* %a) sanitize_address {
@@ -9,8 +9,8 @@ entry:
; CHECK: @read_4_bytes
; CHECK-NOT: ret
; CHECK: lshr {{.*}} 3
-; Check for ASAN's Offset for 64-bit (2^44 or 7fff8000)
-; CHECK-NEXT: {{17592186044416|2147450880}}
+; Check for ASAN's Offset for 64-bit (7fff8000)
+; CHECK-NEXT: add{{.*}}2147450880
; CHECK: ret
define void @example_atomicrmw(i64* %ptr) nounwind uwtable sanitize_address {
@@ -26,7 +26,7 @@ entry:
define void @example_cmpxchg(i64* %ptr, i64 %compare_to, i64 %new_value) nounwind uwtable sanitize_address {
entry:
- %0 = cmpxchg i64* %ptr, i64 %compare_to, i64 %new_value seq_cst
+ %0 = cmpxchg i64* %ptr, i64 %compare_to, i64 %new_value seq_cst seq_cst
ret void
}