Skip to content

Commit bed8f9c

Browse files
committed
sanitizers: Stabilize the no_sanitize attribute
Stabilize the `no_sanitize` attribute so stable sanitizers can also be selectively disabled for annotated functions.
1 parent c7d726f commit bed8f9c

File tree

20 files changed

+17
-74
lines changed

20 files changed

+17
-74
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ declare_features! (
302302
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490)),
303303
/// Allows using non lexical lifetimes (RFC 2094).
304304
(accepted, nll, "1.63.0", Some(43234)),
305+
/// Allows the use of `no_sanitize` attribute.
306+
(accepted, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699)),
305307
/// Allows using `#![no_std]`.
306308
(accepted, no_std, "1.6.0", None),
307309
/// Allows defining identifiers beyond ASCII.

compiler/rustc_feature/src/builtin_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
475475
),
476476
ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
477477
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No),
478-
gated!(
478+
ungated!(
479479
no_sanitize, Normal,
480480
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
481-
EncodeCrossCrate::No, experimental!(no_sanitize)
481+
EncodeCrossCrate::No
482482
),
483483
gated!(
484484
coverage, Normal, template!(OneOf: &[sym::off, sym::on]),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,6 @@ declare_features! (
553553
(unstable, never_type_fallback, "1.41.0", Some(65992)),
554554
/// Allows `#![no_core]`.
555555
(unstable, no_core, "1.3.0", Some(29639)),
556-
/// Allows the use of `no_sanitize` attribute.
557-
(unstable, no_sanitize, "1.42.0", Some(39699)),
558556
/// Allows using the `non_exhaustive_omitted_patterns` lint.
559557
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
560558
/// Allows `for<T>` binders in where-clauses

compiler/rustc_lint_defs/src/builtin.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2439,8 +2439,6 @@ declare_lint! {
24392439
/// ### Example
24402440
///
24412441
/// ```rust
2442-
/// #![feature(no_sanitize)]
2443-
///
24442442
/// #[inline(always)]
24452443
/// #[no_sanitize(address)]
24462444
/// fn x() {}

library/core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
// Do not check link redundancy on bootstraping phase
105105
#![allow(rustdoc::redundant_explicit_links)]
106106
#![warn(rustdoc::unescaped_backticks)]
107+
// FIXME: Remove after `no_sanitize` stabilization (along with `#![feature(no_sanitize)]`)
108+
#![allow(stable_features)]
107109
//
108110
// Library features:
109111
// tidy-alphabetical-start

library/std/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@
263263
#![deny(ffi_unwind_calls)]
264264
// std may use features in a platform-specific way
265265
#![allow(unused_features)]
266+
// FIXME: Remove after `no_sanitize` stabilization (along with `#![feature(no_sanitize)]`)
267+
#![allow(stable_features)]
266268
//
267269
// Features:
268270
#![cfg_attr(not(bootstrap), feature(autodiff))]

src/doc/unstable-book/src/language-features/no-sanitize.md

-29
This file was deleted.

tests/codegen/sanitizer/cfi/emit-type-checks-attr-no-sanitize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zunstable-options -Csanitize=cfi -Copt-level=0
55

66
#![crate_type = "lib"]
7-
#![feature(no_sanitize)]
87

98
#[no_sanitize(cfi)]
109
pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {

tests/codegen/sanitizer/no-sanitize-inlining.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//@[LSAN] compile-flags: -Zunstable-options -Csanitize=leak
1010

1111
#![crate_type = "lib"]
12-
#![feature(no_sanitize)]
13-
1412
// ASAN-LABEL: define void @test
1513
// ASAN: call {{.*}} @random_inline
1614
// ASAN: }

tests/codegen/sanitizer/no-sanitize.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//@ compile-flags: -Zunstable-options -Csanitize=address -Ctarget-feature=-crt-static -Copt-level=0
66

77
#![crate_type = "lib"]
8-
#![feature(no_sanitize)]
9-
108
// CHECK-LABEL: ; no_sanitize::unsanitized
119
// CHECK-NEXT: ; Function Attrs:
1210
// CHECK-NOT: sanitize_address

tests/codegen/sanitizer/scs-attr-check.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//@ compile-flags: -Zunstable-options -Csanitize=shadow-call-stack
66

77
#![crate_type = "lib"]
8-
#![feature(no_sanitize)]
9-
108
// CHECK: ; sanitizer_scs_attr_check::scs
119
// CHECK-NEXT: ; Function Attrs:{{.*}}shadowcallstack
1210
pub fn scs() {}

tests/mir-opt/inline/inline_compatibility.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ compile-flags: -Cpanic=abort
44

55
#![crate_type = "lib"]
6-
#![feature(no_sanitize)]
76
#![feature(target_feature_11)]
87
#![feature(c_variadic)]
98

tests/ui/attributes/no-sanitize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(no_sanitize)]
21
#![feature(stmt_expr_attributes)]
32
#![deny(unused_attributes)]
43
#![allow(dead_code)]

tests/ui/attributes/no-sanitize.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: attribute should be applied to a function definition
2-
--> $DIR/no-sanitize.rs:7:5
2+
--> $DIR/no-sanitize.rs:6:5
33
|
44
LL | #[no_sanitize(memory)]
55
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -9,39 +9,39 @@ LL | | };
99
| |_____- not a function definition
1010

1111
error: attribute should be applied to a function definition
12-
--> $DIR/no-sanitize.rs:13:1
12+
--> $DIR/no-sanitize.rs:12:1
1313
|
1414
LL | #[no_sanitize(memory)]
1515
| ^^^^^^^^^^^^^^^^^^^^^^
1616
LL | type InvalidTy = ();
1717
| -------------------- not a function definition
1818

1919
error: attribute should be applied to a function definition
20-
--> $DIR/no-sanitize.rs:16:1
20+
--> $DIR/no-sanitize.rs:15:1
2121
|
2222
LL | #[no_sanitize(memory)]
2323
| ^^^^^^^^^^^^^^^^^^^^^^
2424
LL | mod invalid_module {}
2525
| --------------------- not a function definition
2626

2727
error: attribute should be applied to a function definition
28-
--> $DIR/no-sanitize.rs:20:13
28+
--> $DIR/no-sanitize.rs:19:13
2929
|
3030
LL | let _ = #[no_sanitize(memory)]
3131
| ^^^^^^^^^^^^^^^^^^^^^^
3232
LL | (|| 1);
3333
| ------ not a function definition
3434

3535
error: attribute should be applied to a function definition
36-
--> $DIR/no-sanitize.rs:24:1
36+
--> $DIR/no-sanitize.rs:23:1
3737
|
3838
LL | #[no_sanitize(memory)]
3939
| ^^^^^^^^^^^^^^^^^^^^^^
4040
LL | struct F;
4141
| --------- not a function definition
4242

4343
error: attribute should be applied to a function definition
44-
--> $DIR/no-sanitize.rs:27:1
44+
--> $DIR/no-sanitize.rs:26:1
4545
|
4646
LL | #[no_sanitize(memory)]
4747
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/feature-gates/feature-gate-no_sanitize.rs

-4
This file was deleted.

tests/ui/feature-gates/feature-gate-no_sanitize.stderr

-13
This file was deleted.
-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(no_sanitize)]
2-
31
#[no_sanitize(brontosaurus)] //~ ERROR invalid argument
42
fn main() {
53
}

tests/ui/invalid/invalid-no-sanitize.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: invalid argument for `no_sanitize`
2-
--> $DIR/invalid-no-sanitize.rs:3:15
2+
--> $DIR/invalid-no-sanitize.rs:1:15
33
|
44
LL | #[no_sanitize(brontosaurus)]
55
| ^^^^^^^^^^^^

tests/ui/sanitizer/inline-always.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(no_sanitize)]
4-
53
#[inline(always)]
64
//~^ NOTE inlining requested here
75
#[no_sanitize(address)]

tests/ui/sanitizer/inline-always.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: `no_sanitize` will have no effect after inlining
2-
--> $DIR/inline-always.rs:7:1
2+
--> $DIR/inline-always.rs:5:1
33
|
44
LL | #[no_sanitize(address)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: inlining requested here
8-
--> $DIR/inline-always.rs:5:1
8+
--> $DIR/inline-always.rs:3:1
99
|
1010
LL | #[inline(always)]
1111
| ^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)