about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-07 17:00:16 +0100
committerGitHub <noreply@github.com>2020-02-07 17:00:16 +0100
commit2f1eaeea772c2800cd45d263a6927db366f5bdc5 (patch)
tree1f9f6d8e4553a4a0cee6a539eb2767bcf9259d09 /src/test/codegen
parentb5e21dbb5cabdaaadc47a4d8e3f59979dcad2871 (diff)
parent80adde2e337f4e0d784da401b2db37c5d4d3468b (diff)
downloadrust-2f1eaeea772c2800cd45d263a6927db366f5bdc5.tar.gz
rust-2f1eaeea772c2800cd45d263a6927db366f5bdc5.zip
Rollup merge of #68164 - tmiasko:no-sanitize, r=nikomatsakis
Selectively disable sanitizer instrumentation

Add `no_sanitize` attribute that allows to opt out from sanitizer
instrumentation in an annotated function.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/sanitizer-no-sanitize-inlining.rs32
-rw-r--r--src/test/codegen/sanitizer-no-sanitize.rs29
2 files changed, 61 insertions, 0 deletions
diff --git a/src/test/codegen/sanitizer-no-sanitize-inlining.rs b/src/test/codegen/sanitizer-no-sanitize-inlining.rs
new file mode 100644
index 00000000000..d96e76618d3
--- /dev/null
+++ b/src/test/codegen/sanitizer-no-sanitize-inlining.rs
@@ -0,0 +1,32 @@
+// Verifies that no_sanitize attribute prevents inlining when
+// given sanitizer is enabled, but has no effect on inlining otherwise.
+//
+// needs-sanitizer-support
+// only-x86_64
+//
+// revisions: ASAN LSAN
+//
+//[ASAN] compile-flags: -Zsanitizer=address -C opt-level=3 -Z mir-opt-level=3
+//[LSAN] compile-flags: -Zsanitizer=leak    -C opt-level=3 -Z mir-opt-level=3
+
+#![crate_type="lib"]
+#![feature(no_sanitize)]
+
+// ASAN-LABEL: define void @test
+// ASAN:         tail call fastcc void @random_inline
+// ASAN:       }
+//
+// LSAN-LABEL: define void @test
+// LSAN-NO:      call
+// LSAN:       }
+#[no_mangle]
+pub fn test(n: &mut u32) {
+    random_inline(n);
+}
+
+#[no_sanitize(address)]
+#[inline]
+#[no_mangle]
+pub fn random_inline(n: &mut u32) {
+    *n = 42;
+}
diff --git a/src/test/codegen/sanitizer-no-sanitize.rs b/src/test/codegen/sanitizer-no-sanitize.rs
new file mode 100644
index 00000000000..dfceb28c8dd
--- /dev/null
+++ b/src/test/codegen/sanitizer-no-sanitize.rs
@@ -0,0 +1,29 @@
+// Verifies that no_sanitze attribute can be used to
+// selectively disable sanitizer instrumentation.
+//
+// needs-sanitizer-support
+// compile-flags: -Zsanitizer=address
+
+#![crate_type="lib"]
+#![feature(no_sanitize)]
+
+// CHECK-LABEL: ; sanitizer_no_sanitize::unsanitized
+// CHECK-NEXT:  ; Function Attrs:
+// CHECK-NOT:   sanitize_address
+// CHECK:       start:
+// CHECK-NOT:   call void @__asan_report_load
+// CHECK:       }
+#[no_sanitize(address)]
+pub fn unsanitized(b: &mut u8) -> u8 {
+    *b
+}
+
+// CHECK-LABEL: ; sanitizer_no_sanitize::sanitized
+// CHECK-NEXT:  ; Function Attrs:
+// CHECK:       sanitize_address
+// CHECK:       start:
+// CHECK:       call void @__asan_report_load
+// CHECK:       }
+pub fn sanitized(b: &mut u8) -> u8 {
+    *b
+}