From b846b42c8dcf052eabda71d416a986a7891093f7 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Sun, 12 Jan 2020 00:00:00 +0000 Subject: Selectively disable sanitizer instrumentation Add `no_sanitize` attribute that allows to opt out from sanitizer instrumentation in an annotated function. --- src/test/codegen/sanitizer-no-sanitize-inlining.rs | 32 ++++++++++++++++++++++ src/test/codegen/sanitizer-no-sanitize.rs | 29 ++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/test/codegen/sanitizer-no-sanitize-inlining.rs create mode 100644 src/test/codegen/sanitizer-no-sanitize.rs (limited to 'src/test/codegen') 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 +} -- cgit 1.4.1-3-g733a5