Skip to content

Commit 99cd982

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 d3d029c commit 99cd982

File tree

19 files changed

+18
-75
lines changed

19 files changed

+18
-75
lines changed

Diff for: compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ declare_features! (
309309
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490)),
310310
/// Allows using non lexical lifetimes (RFC 2094).
311311
(accepted, nll, "1.63.0", Some(43234)),
312+
/// Allows the use of `no_sanitize` attribute.
313+
(accepted, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699)),
312314
/// Allows using `#![no_std]`.
313315
(accepted, no_std, "1.6.0", None),
314316
/// Allows defining identifiers beyond ASCII.

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

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

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,6 @@ declare_features! (
572572
(unstable, never_type_fallback, "1.41.0", Some(65992)),
573573
/// Allows `#![no_core]`.
574574
(unstable, no_core, "1.3.0", Some(29639)),
575-
/// Allows the use of `no_sanitize` attribute.
576-
(unstable, no_sanitize, "1.42.0", Some(39699)),
577575
/// Allows using the `non_exhaustive_omitted_patterns` lint.
578576
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
579577
/// Allows `for<T>` binders in where-clauses

Diff for: compiler/rustc_lint_defs/src/builtin.rs

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

Diff for: library/core/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
#![feature(variant_count)]
140140
// tidy-alphabetical-end
141141
//
142+
// Features:
143+
#![cfg_attr(bootstrap, feature(no_sanitize))]
144+
//
142145
// Language features:
143146
// tidy-alphabetical-start
144147
#![feature(abi_unadjusted)]
@@ -177,7 +180,6 @@
177180
#![feature(negative_impls)]
178181
#![feature(never_type)]
179182
#![feature(no_core)]
180-
#![feature(no_sanitize)]
181183
#![feature(optimize_attribute)]
182184
#![feature(prelude_import)]
183185
#![feature(repr_simd)]

Diff for: library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
#![allow(unused_features)]
262262
//
263263
// Features:
264+
#![cfg_attr(bootstrap, feature(no_sanitize))]
264265
#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
265266
#![cfg_attr(
266267
all(target_vendor = "fortanix", target_env = "sgx"),
@@ -304,7 +305,6 @@
304305
#![feature(needs_panic_runtime)]
305306
#![feature(negative_impls)]
306307
#![feature(never_type)]
307-
#![feature(no_sanitize)]
308308
#![feature(optimize_attribute)]
309309
#![feature(prelude_import)]
310310
#![feature(rustc_attrs)]

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

-29
This file was deleted.

Diff for: 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 {

Diff for: 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: }

Diff for: 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() {}

Diff for: 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

Diff for: 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)]

Diff for: tests/ui/attributes/no-sanitize.stderr

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

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

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

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

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

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

5454
error: `#[no_sanitize(memory)]` should be applied to a function
55-
--> $DIR/no-sanitize.rs:33:24
55+
--> $DIR/no-sanitize.rs:32:24
5656
|
5757
LL | #[no_sanitize(address, memory)]
5858
| ^^^^^^

Diff for: tests/ui/feature-gates/feature-gate-no_sanitize.rs

-4
This file was deleted.

Diff for: tests/ui/feature-gates/feature-gate-no_sanitize.stderr

-13
This file was deleted.

Diff for: tests/ui/invalid/invalid-no-sanitize.rs

-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
}

Diff for: 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
| ^^^^^^^^^^^^

Diff for: 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)]

Diff for: 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)