diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-01-12 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-02-05 23:30:38 +0100 |
| commit | b846b42c8dcf052eabda71d416a986a7891093f7 (patch) | |
| tree | fd4f1b3e820fe93dc523e21a72482cca20ebb7e4 /src/test/codegen | |
| parent | eda1a7adfcf6de70afa4ca0a6f709ed0e507516a (diff) | |
| download | rust-b846b42c8dcf052eabda71d416a986a7891093f7.tar.gz rust-b846b42c8dcf052eabda71d416a986a7891093f7.zip | |
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.rs | 32 | ||||
| -rw-r--r-- | src/test/codegen/sanitizer-no-sanitize.rs | 29 |
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 +} |
