about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-26 01:54:53 +0000
committerbors <bors@rust-lang.org>2019-11-26 01:54:53 +0000
commit2626f3d3d5c3007745176aa0fe22781b9ec2bb06 (patch)
treee793260388f0fa9a15bc39e7b80d55252096ae77 /src/test/codegen
parent483a83b6e648d9e6cb21af75dba289a9aef150b1 (diff)
parentbf121a33c4f9c3361e29545c6448e603952e6944 (diff)
downloadrust-2626f3d3d5c3007745176aa0fe22781b9ec2bb06.tar.gz
rust-2626f3d3d5c3007745176aa0fe22781b9ec2bb06.zip
Auto merge of #66522 - tmiasko:sanitize-flags, r=alexcrichton
Add support for sanitizer recover and tracking origins of uninitialized memory

* Add support for sanitizer recovery `-Zsanitizer-recover=...` (equivalent to `-fsanitize-recover` in clang).
* Add support for tracking origins of uninitialized memory in MemorySanitizer `-Zsanitizer-memory-track-origins` (equivalent to `-fsanitize-memory-track-origins` in clang).
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/sanitizer-memory-track-orgins.rs28
-rw-r--r--src/test/codegen/sanitizer-recover.rs34
2 files changed, 62 insertions, 0 deletions
diff --git a/src/test/codegen/sanitizer-memory-track-orgins.rs b/src/test/codegen/sanitizer-memory-track-orgins.rs
new file mode 100644
index 00000000000..fd8be0bced7
--- /dev/null
+++ b/src/test/codegen/sanitizer-memory-track-orgins.rs
@@ -0,0 +1,28 @@
+// Verifies that MemorySanitizer track-origins level can be controlled
+// with -Zsanitizer-memory-track-origins option.
+//
+// needs-sanitizer-support
+// only-linux
+// only-x86_64
+// revisions:MSAN-0 MSAN-1 MSAN-2
+//
+//[MSAN-0] compile-flags: -Zsanitizer=memory
+//[MSAN-1] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins=1
+//[MSAN-2] compile-flags: -Zsanitizer=memory -Zsanitizer-memory-track-origins
+
+#![crate_type="lib"]
+
+// MSAN-0-NOT: @__msan_track_origins
+// MSAN-1:     @__msan_track_origins = weak_odr local_unnamed_addr constant i32 1
+// MSAN-2:     @__msan_track_origins = weak_odr local_unnamed_addr constant i32 2
+//
+// MSAN-0-LABEL: define void @copy(
+// MSAN-1-LABEL: define void @copy(
+// MSAN-2-LABEL: define void @copy(
+#[no_mangle]
+pub fn copy(dst: &mut i32, src: &i32) {
+    // MSAN-0-NOT: call i32 @__msan_chain_origin(
+    // MSAN-1-NOT: call i32 @__msan_chain_origin(
+    // MSAN-2:     call i32 @__msan_chain_origin(
+    *dst = *src;
+}
diff --git a/src/test/codegen/sanitizer-recover.rs b/src/test/codegen/sanitizer-recover.rs
new file mode 100644
index 00000000000..a292332667b
--- /dev/null
+++ b/src/test/codegen/sanitizer-recover.rs
@@ -0,0 +1,34 @@
+// Verifies that AddressSanitizer and MemorySanitizer
+// recovery mode can be enabled with -Zsanitizer-recover.
+//
+// needs-sanitizer-support
+// only-linux
+// only-x86_64
+// revisions:ASAN ASAN-RECOVER MSAN MSAN-RECOVER
+//
+//[ASAN]         compile-flags: -Zsanitizer=address
+//[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address
+//[MSAN]         compile-flags: -Zsanitizer=memory
+//[MSAN-RECOVER] compile-flags: -Zsanitizer=memory  -Zsanitizer-recover=memory
+
+#![crate_type="lib"]
+
+// ASAN-LABEL:         define i32 @penguin(
+// ASAN-RECOVER-LABEL: define i32 @penguin(
+// MSAN-LABEL:         define i32 @penguin(
+// MSAN-RECOVER-LABEL: define i32 @penguin(
+#[no_mangle]
+pub fn penguin(p: &mut i32) -> i32 {
+    // ASAN:             call void @__asan_report_load4(i64 %0)
+    // ASAN:             unreachable
+    //
+    // ASAN-RECOVER:     call void @__asan_report_load4_noabort(
+    // ASAN-RECOVER-NOT: unreachable
+    //
+    // MSAN:             call void @__msan_warning_noreturn()
+    // MSAN:             unreachable
+    //
+    // MSAN-RECOVER:     call void @__msan_warning()
+    // MSAN-RECOVER-NOT: unreachable
+    *p
+}