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 Dec 13, 2024
1 parent 970d047 commit 8e536af
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 73 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 @@ -307,6 +307,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 @@ -565,8 +565,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 @@ -2440,8 +2440,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 @@ -260,6 +260,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/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
1 change: 0 additions & 1 deletion tests/ui/attributes/no-sanitize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(no_sanitize)]
#![feature(stmt_expr_attributes)]
#![deny(unused_attributes)]
#![allow(dead_code)]
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/attributes/no-sanitize.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:7:19
--> $DIR/no-sanitize.rs:6:19
|
LL | #[no_sanitize(memory)]
| ^^^^^^
Expand All @@ -9,39 +9,39 @@ LL | | };
| |_____- not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:13:15
--> $DIR/no-sanitize.rs:12:15
|
LL | #[no_sanitize(memory)]
| ^^^^^^
LL | type InvalidTy = ();
| -------------------- not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:16:15
--> $DIR/no-sanitize.rs:15:15
|
LL | #[no_sanitize(memory)]
| ^^^^^^
LL | mod invalid_module {}
| --------------------- not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:20:27
--> $DIR/no-sanitize.rs:19:27
|
LL | let _ = #[no_sanitize(memory)]
| ^^^^^^
LL | (|| 1);
| ------ not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:24:15
--> $DIR/no-sanitize.rs:23:15
|
LL | #[no_sanitize(memory)]
| ^^^^^^
LL | struct F;
| --------- not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:27:15
--> $DIR/no-sanitize.rs:26:15
|
LL | #[no_sanitize(memory)]
| ^^^^^^
Expand All @@ -52,7 +52,7 @@ LL | | }
| |_- not a function

error: `#[no_sanitize(memory)]` should be applied to a function
--> $DIR/no-sanitize.rs:33:24
--> $DIR/no-sanitize.rs:32:24
|
LL | #[no_sanitize(address, memory)]
| ^^^^^^
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 8e536af

Please sign in to comment.