Skip to content

Commit 1b89895

Browse files
committed
Remove the no_sanitize attribute in favor of sanitize
This removes the #[no_sanitize] attribute, which was behind an unstable feature named no_sanitize. Instead, we introduce the sanitize attribute which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off).
1 parent 0626ad7 commit 1b89895

32 files changed

+131
-407
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ codegen_ssa_invalid_monomorphization_unsupported_symbol = invalid monomorphizati
165165
166166
codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size = invalid monomorphization of `{$name}` intrinsic: unsupported {$symbol} from `{$in_ty}` with element `{$in_elem}` of size `{$size}` to `{$ret_ty}`
167167
168-
codegen_ssa_invalid_no_sanitize = invalid argument for `no_sanitize`
169-
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
170-
171168
codegen_ssa_invalid_sanitize = invalid argument for `sanitize`
172169
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
173170

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
8686
let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);
8787

8888
let mut link_ordinal_span = None;
89-
let mut no_sanitize_span = None;
9089
let mut sanitize_span = None;
9190

9291
for attr in attrs.iter() {
@@ -255,37 +254,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
255254
}
256255
}
257256
}
258-
sym::no_sanitize => {
259-
no_sanitize_span = Some(attr.span());
260-
if let Some(list) = attr.meta_item_list() {
261-
for item in list.iter() {
262-
match item.name() {
263-
Some(sym::address) => {
264-
codegen_fn_attrs.no_sanitize |=
265-
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
266-
}
267-
Some(sym::cfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
268-
Some(sym::kcfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
269-
Some(sym::memory) => {
270-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY
271-
}
272-
Some(sym::memtag) => {
273-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG
274-
}
275-
Some(sym::shadow_call_stack) => {
276-
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
277-
}
278-
Some(sym::thread) => {
279-
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD
280-
}
281-
Some(sym::hwaddress) => {
282-
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
283-
}
284-
_ => {
285-
tcx.dcx().emit_err(errors::InvalidNoSanitize { span: item.span() });
286-
}
287-
}
288-
}
257+
sym::link_ordinal => {
258+
link_ordinal_span = Some(attr.span());
259+
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
260+
codegen_fn_attrs.link_ordinal = ordinal;
289261
}
290262
}
291263
sym::sanitize => sanitize_span = Some(attr.span()),
@@ -455,16 +427,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
455427
tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
456428
}
457429

458-
if !codegen_fn_attrs.no_sanitize.is_empty()
459-
&& codegen_fn_attrs.inline.always()
460-
&& let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span)
461-
{
462-
let hir_id = tcx.local_def_id_to_hir_id(did);
463-
tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, no_sanitize_span, |lint| {
464-
lint.primary_message("`no_sanitize` will have no effect after inlining");
465-
lint.span_note(inline_span, "inlining requested here");
466-
})
467-
}
468430
if !codegen_fn_attrs.no_sanitize.is_empty()
469431
&& codegen_fn_attrs.inline.always()
470432
&& let (Some(sanitize_span), Some(inline_span)) = (sanitize_span, inline_span)

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,14 +1100,6 @@ impl IntoDiagArg for ExpectedPointerMutability {
11001100
}
11011101
}
11021102

1103-
#[derive(Diagnostic)]
1104-
#[diag(codegen_ssa_invalid_no_sanitize)]
1105-
#[note]
1106-
pub(crate) struct InvalidNoSanitize {
1107-
#[primary_span]
1108-
pub span: Span,
1109-
}
1110-
11111103
#[derive(Diagnostic)]
11121104
#[diag(codegen_ssa_invalid_sanitize)]
11131105
#[note]

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
539539
),
540540
ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
541541
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No),
542-
gated!(
543-
no_sanitize, Normal,
544-
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
545-
EncodeCrossCrate::No, experimental!(no_sanitize)
546-
),
547542
gated!(
548543
sanitize, Normal, template!(List: r#"address = "on|off", cfi = "on|off""#), ErrorPreceding,
549544
EncodeCrossCrate::No, sanitize, experimental!(sanitize),

compiler/rustc_feature/src/removed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ declare_features! (
190190
(removed, no_coverage, "1.74.0", Some(84605), Some("renamed to `coverage_attribute`"), 114656),
191191
/// Allows `#[no_debug]`.
192192
(removed, no_debug, "1.43.0", Some(29721), Some("removed due to lack of demand"), 69667),
193+
// Allows the use of `no_sanitize` attribute.
194+
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
195+
(removed, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 1234),
193196
/// Note: this feature was previously recorded in a separate
194197
/// `STABLE_REMOVED` list because it, uniquely, was once stable but was
195198
/// then removed. But there was no utility storing it separately, so now

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,6 @@ declare_features! (
591591
(unstable, new_range, "1.86.0", Some(123741)),
592592
/// Allows `#![no_core]`.
593593
(unstable, no_core, "1.3.0", Some(29639)),
594-
/// Allows the use of `no_sanitize` attribute.
595-
(unstable, no_sanitize, "1.42.0", Some(39699)),
596594
/// Allows using the `non_exhaustive_omitted_patterns` lint.
597595
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
598596
/// Allows `for<T>` binders in where-clauses

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,18 +2298,18 @@ declare_lint! {
22982298

22992299
declare_lint! {
23002300
/// The `inline_no_sanitize` lint detects incompatible use of
2301-
/// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2301+
/// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
23022302
///
23032303
/// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2304-
/// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2304+
/// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
23052305
///
23062306
/// ### Example
23072307
///
23082308
/// ```rust
2309-
/// #![feature(no_sanitize)]
2309+
/// #![feature(sanitize)]
23102310
///
23112311
/// #[inline(always)]
2312-
/// #[no_sanitize(address)]
2312+
/// #[sanitize(address = "off")]
23132313
/// fn x() {}
23142314
///
23152315
/// fn main() {
@@ -2322,11 +2322,11 @@ declare_lint! {
23222322
/// ### Explanation
23232323
///
23242324
/// The use of the [`#[inline(always)]`][inline] attribute prevents the
2325-
/// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2325+
/// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
23262326
/// Consider temporarily removing `inline` attribute.
23272327
pub INLINE_NO_SANITIZE,
23282328
Warn,
2329-
"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2329+
r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
23302330
}
23312331

23322332
declare_lint! {

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct CodegenFnAttrs {
4040
/// The `#[link_section = "..."]` attribute, or what executable section this
4141
/// should be placed in.
4242
pub link_section: Option<Symbol>,
43-
/// The `#[no_sanitize(...)]` attribute. Indicates sanitizers for which
44-
/// instrumentation should be disabled inside the annotated function.
43+
/// The `#[sanitize(xyz = "off")]` attribute. Indicates sanitizers for which
44+
/// instrumentation should be disabled inside the function.
4545
pub no_sanitize: SanitizerSet,
4646
/// The `#[instruction_set(set)]` attribute. Indicates if the generated code should
4747
/// be generated against a specific instruction set. Only usable on architectures which allow

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,6 @@ passes_no_mangle_foreign =
537537
.note = symbol names in extern blocks are not mangled
538538
.suggestion = remove this attribute
539539
540-
passes_no_sanitize =
541-
`#[no_sanitize({$attr_str})]` should be applied to {$accepted_kind}
542-
.label = not {$accepted_kind}
543-
544540
passes_non_exhaustive_with_default_field_values =
545541
`#[non_exhaustive]` can't be used to annotate items with default field values
546542
.label = this struct has default field values
@@ -553,7 +549,7 @@ passes_object_lifetime_err =
553549
{$repr}
554550
555551
passes_only_has_effect_on =
556-
`#[{$attr_name}]` only has an effect on {$target_name ->
552+
`#[{$attr_name}]` only has an effect on {$passes_only_has_effect_on ->
557553
[function] functions
558554
[module] modules
559555
[implementation_block] implementation blocks

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
292292
self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
293293
}
294294
[sym::coverage, ..] => self.check_coverage(attr, span, target),
295-
[sym::no_sanitize, ..] => {
296-
self.check_no_sanitize(attr, span, target)
297-
}
298295
[sym::sanitize, ..] => {
299296
self.check_sanitize(attr, span, target)
300297
}
@@ -635,42 +632,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
635632
}
636633
}
637634

638-
fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
639-
if let Some(list) = attr.meta_item_list() {
640-
for item in list.iter() {
641-
let sym = item.name();
642-
match sym {
643-
Some(s @ sym::address | s @ sym::hwaddress) => {
644-
let is_valid =
645-
matches!(target, Target::Fn | Target::Method(..) | Target::Static);
646-
if !is_valid {
647-
self.dcx().emit_err(errors::NoSanitize {
648-
attr_span: item.span(),
649-
defn_span: span,
650-
accepted_kind: "a function or static",
651-
attr_str: s.as_str(),
652-
});
653-
}
654-
}
655-
_ => {
656-
let is_valid = matches!(target, Target::Fn | Target::Method(..));
657-
if !is_valid {
658-
self.dcx().emit_err(errors::NoSanitize {
659-
attr_span: item.span(),
660-
defn_span: span,
661-
accepted_kind: "a function",
662-
attr_str: &match sym {
663-
Some(name) => name.to_string(),
664-
None => "...".to_string(),
665-
},
666-
});
667-
}
668-
}
669-
}
670-
}
671-
}
672-
}
673-
674635
/// Checks that the `#[sanitize(..)]` attribute is applied to a
675636
/// function/closure/method, or to an impl block or module.
676637
fn check_sanitize(&self, attr: &Attribute, target_span: Span, target: Target) {

0 commit comments

Comments
 (0)