Skip to content

Commit

Permalink
sanitizers: Stabilize the no_sanitize attribute
Browse files Browse the repository at this point in the history
Stabilize the `no_sanitize` attribute so stable sanitizers can also be
selectively disabled for annotated functions.
  • Loading branch information
rcvalle committed Aug 7, 2024
1 parent 9ee702b commit 8af3b93
Show file tree
Hide file tree
Showing 18 changed files with 11 additions and 67 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ declare_features! (
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490)),
/// Allows using non lexical lifetimes (RFC 2094).
(accepted, nll, "1.63.0", Some(43234)),
/// Allows the use of `no_sanitize` attribute.
(accepted, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699)),
/// Allows using `#![no_std]`.
(accepted, no_std, "1.6.0", None),
/// Allows defining identifiers beyond ASCII.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No),
gated!(
ungated!(
no_sanitize, Normal,
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
EncodeCrossCrate::No, experimental!(no_sanitize)
EncodeCrossCrate::No
),
gated!(
coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,6 @@ declare_features! (
(unstable, never_type_fallback, "1.41.0", Some(65992)),
/// Allows `#![no_core]`.
(unstable, no_core, "1.3.0", Some(29639)),
/// Allows the use of `no_sanitize` attribute.
(unstable, no_sanitize, "1.42.0", Some(39699)),
/// Allows using the `non_exhaustive_omitted_patterns` lint.
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
/// Allows `for<T>` binders in where-clauses
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(no_sanitize)]
///
/// #[inline(always)]
/// #[no_sanitize(address)]
/// fn x() {}
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
// Do not check link redundancy on bootstraping phase
#![allow(rustdoc::redundant_explicit_links)]
#![warn(rustdoc::unescaped_backticks)]
// FIXME: Remove after `no_sanitize` stabilization (along with `#![feature(no_sanitize)]`)
#![allow(stable_features)]
//
// Library features:
// tidy-alphabetical-start
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@
#![deny(ffi_unwind_calls)]
// std may use features in a platform-specific way
#![allow(unused_features)]
// FIXME: Remove after `no_sanitize` stabilization (along with `#![feature(no_sanitize)]`)
#![allow(stable_features)]
//
// Features:
#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
Expand Down
29 changes: 0 additions & 29 deletions src/doc/unstable-book/src/language-features/no-sanitize.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zunstable-options -Csanitize=cfi -Copt-level=0

#![crate_type = "lib"]
#![feature(no_sanitize)]

#[no_sanitize(cfi)]
pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen/sanitizer/no-sanitize-inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//@[LSAN] compile-flags: -Zunstable-options -Csanitize=leak

#![crate_type = "lib"]
#![feature(no_sanitize)]

// ASAN-LABEL: define void @test
// ASAN: call {{.*}} @random_inline
// ASAN: }
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen/sanitizer/no-sanitize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//@ compile-flags: -Zunstable-options -Csanitize=address -Ctarget-feature=-crt-static -Copt-level=0

#![crate_type = "lib"]
#![feature(no_sanitize)]

// CHECK-LABEL: ; no_sanitize::unsanitized
// CHECK-NEXT: ; Function Attrs:
// CHECK-NOT: sanitize_address
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen/sanitizer/scs-attr-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//@ compile-flags: -Zunstable-options -Csanitize=shadow-call-stack

#![crate_type = "lib"]
#![feature(no_sanitize)]

// CHECK: ; sanitizer_scs_attr_check::scs
// CHECK-NEXT: ; Function Attrs:{{.*}}shadowcallstack
pub fn scs() {}
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/inline/inline_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//@ compile-flags: -Cpanic=abort

#![crate_type = "lib"]
#![feature(no_sanitize)]
#![feature(target_feature_11)]
#![feature(c_variadic)]

Expand Down
4 changes: 0 additions & 4 deletions tests/ui/feature-gates/feature-gate-no_sanitize.rs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/ui/feature-gates/feature-gate-no_sanitize.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/invalid/invalid-no-sanitize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(no_sanitize)]

#[no_sanitize(brontosaurus)] //~ ERROR invalid argument
fn main() {
}
2 changes: 1 addition & 1 deletion tests/ui/invalid/invalid-no-sanitize.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: invalid argument for `no_sanitize`
--> $DIR/invalid-no-sanitize.rs:3:15
--> $DIR/invalid-no-sanitize.rs:1:15
|
LL | #[no_sanitize(brontosaurus)]
| ^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/sanitizer/inline-always.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(no_sanitize)]

#[inline(always)]
//~^ NOTE inlining requested here
#[no_sanitize(address)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/sanitizer/inline-always.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
warning: `no_sanitize` will have no effect after inlining
--> $DIR/inline-always.rs:7:1
--> $DIR/inline-always.rs:5:1
|
LL | #[no_sanitize(address)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: inlining requested here
--> $DIR/inline-always.rs:5:1
--> $DIR/inline-always.rs:3:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 8af3b93

Please sign in to comment.