From 5d1a3023fa028dde19fbed70266527be9243d21c Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 25 Jun 2026 13:24:25 +0000 Subject: [PATCH 01/29] sess: remove target modifier implementation The existing implementation of target modifiers is quite complicated and hard to work with because it relies so heavily on macros. To some extent, this is unavoidable because only a subset of the `UnstableOptions` or `CodegenOptions` flags are target modifiers and so it needs to filter for those. A simpler implementation will be possible given the additional constraint that all target modifier options are in the same group. --- compiler/rustc_metadata/src/creader.rs | 141 +------- compiler/rustc_metadata/src/diagnostics.rs | 97 ------ compiler/rustc_metadata/src/rmeta/decoder.rs | 36 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 10 +- compiler/rustc_metadata/src/rmeta/mod.rs | 5 +- .../rustc_metadata/src/rmeta/parameterized.rs | 1 - compiler/rustc_session/src/config.rs | 6 - compiler/rustc_session/src/lib.rs | 1 - compiler/rustc_session/src/options.rs | 315 ++---------------- src/librustdoc/config.rs | 8 +- src/librustdoc/core.rs | 2 - src/librustdoc/doctest.rs | 1 - 12 files changed, 28 insertions(+), 595 deletions(-) diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 6543b5700192e..b5545a0642d32 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -23,10 +23,7 @@ use rustc_middle::ty::data_structures::IndexSet; use rustc_middle::ty::{TyCtxt, TyCtxtFeed}; use rustc_proc_macro::bridge::client::Client as ProcMacroClient; use rustc_session::config::mitigation_coverage::DeniedPartialMitigationLevel; -use rustc_session::config::{ - CrateType, ExtendedTargetModifierInfo, ExternLocation, Externs, OptionsTargetModifiers, - TargetModifier, -}; +use rustc_session::config::{CrateType, ExternLocation, Externs}; use rustc_session::output::validate_crate_name; use rustc_session::search_paths::PathKind; use rustc_session::{Session, lint}; @@ -38,9 +35,7 @@ use tracing::{debug, info}; use crate::diagnostics; use crate::locator::{CrateError, CrateLocator, CratePaths, CrateRejections}; -use crate::rmeta::{ - CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob, TargetModifiers, -}; +use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob}; /// The backend's way to give the crate store access to the metadata in a library. /// Note that it returns the raw metadata bytes stored in the library file, whether @@ -342,143 +337,11 @@ impl CStore { } } - fn report_target_modifiers_extended( - tcx: TyCtxt<'_>, - krate: &Crate, - mods: &TargetModifiers, - dep_mods: &TargetModifiers, - data: &CrateMetadata, - ) { - let span = krate.spans.inner_span.shrink_to_lo(); - let allowed_flag_mismatches = &tcx.sess.opts.cg.unsafe_allow_abi_mismatch; - let local_crate = tcx.crate_name(LOCAL_CRATE); - let tmod_extender = |tmod: &TargetModifier| (tmod.extend(), tmod.clone()); - let report_diff = |prefix: &String, - opt_name: &String, - flag_local_value: Option<&String>, - flag_extern_value: Option<&String>| { - if allowed_flag_mismatches.contains(&opt_name) { - return; - } - let extern_crate = data.name(); - let flag_name = opt_name.clone(); - let flag_name_prefixed = format!("-{}{}", prefix, opt_name); - - match (flag_local_value, flag_extern_value) { - (Some(local_value), Some(extern_value)) => { - tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiers { - span, - extern_crate, - local_crate, - flag_name, - flag_name_prefixed, - local_value: local_value.to_string(), - extern_value: extern_value.to_string(), - }) - } - (None, Some(extern_value)) => { - tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiersLMissed { - span, - extern_crate, - local_crate, - flag_name, - flag_name_prefixed, - extern_value: extern_value.to_string(), - has_extern_value: !extern_value.is_empty(), - }) - } - (Some(local_value), None) => { - tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiersRMissed { - span, - extern_crate, - local_crate, - flag_name, - flag_name_prefixed, - local_value: local_value.to_string(), - has_local_value: !local_value.is_empty(), - }) - } - (None, None) => panic!("Incorrect target modifiers report_diff(None, None)"), - }; - }; - let mut it1 = mods.iter().map(tmod_extender); - let mut it2 = dep_mods.iter().map(tmod_extender); - let mut left_name_val: Option<(ExtendedTargetModifierInfo, TargetModifier)> = None; - let mut right_name_val: Option<(ExtendedTargetModifierInfo, TargetModifier)> = None; - loop { - left_name_val = left_name_val.or_else(|| it1.next()); - right_name_val = right_name_val.or_else(|| it2.next()); - match (&left_name_val, &right_name_val) { - (Some(l), Some(r)) => match l.1.opt.cmp(&r.1.opt) { - cmp::Ordering::Equal => { - if !l.1.consistent(&tcx.sess, Some(&r.1)) { - report_diff( - &l.0.prefix, - &l.0.name, - Some(&l.1.value_name), - Some(&r.1.value_name), - ); - } - left_name_val = None; - right_name_val = None; - } - cmp::Ordering::Greater => { - if !r.1.consistent(&tcx.sess, None) { - report_diff(&r.0.prefix, &r.0.name, None, Some(&r.1.value_name)); - } - right_name_val = None; - } - cmp::Ordering::Less => { - if !l.1.consistent(&tcx.sess, None) { - report_diff(&l.0.prefix, &l.0.name, Some(&l.1.value_name), None); - } - left_name_val = None; - } - }, - (Some(l), None) => { - if !l.1.consistent(&tcx.sess, None) { - report_diff(&l.0.prefix, &l.0.name, Some(&l.1.value_name), None); - } - left_name_val = None; - } - (None, Some(r)) => { - if !r.1.consistent(&tcx.sess, None) { - report_diff(&r.0.prefix, &r.0.name, None, Some(&r.1.value_name)); - } - right_name_val = None; - } - (None, None) => break, - } - } - } - pub fn report_session_incompatibilities(&self, tcx: TyCtxt<'_>, krate: &Crate) { - self.report_incompatible_target_modifiers(tcx, krate); self.report_incompatible_partial_mitigations(tcx, krate); self.report_incompatible_async_drop_feature(tcx, krate); } - pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>, krate: &Crate) { - for flag_name in &tcx.sess.opts.cg.unsafe_allow_abi_mismatch { - if !OptionsTargetModifiers::is_target_modifier(flag_name) { - tcx.dcx().emit_err(diagnostics::UnknownTargetModifierUnsafeAllowed { - span: krate.spans.inner_span.shrink_to_lo(), - flag_name: flag_name.clone(), - }); - } - } - let mods = tcx.sess.opts.gather_target_modifiers(); - for (_cnum, data) in self.iter_crate_data() { - if data.is_proc_macro_crate() { - continue; - } - let dep_mods = data.target_modifiers(); - if mods != dep_mods { - Self::report_target_modifiers_extended(tcx, krate, &mods, &dep_mods, data); - } - } - } - pub fn report_incompatible_partial_mitigations(&self, tcx: TyCtxt<'_>, krate: &Crate) { let my_mitigations = tcx.sess.gather_enabled_denied_partial_mitigations(); let mut my_mitigations: BTreeMap<_, _> = diff --git a/compiler/rustc_metadata/src/diagnostics.rs b/compiler/rustc_metadata/src/diagnostics.rs index 8fc2b27bde8e4..1ce564861f2b9 100644 --- a/compiler/rustc_metadata/src/diagnostics.rs +++ b/compiler/rustc_metadata/src/diagnostics.rs @@ -535,103 +535,6 @@ pub(crate) struct WasmCAbi { pub span: Span, } -#[derive(Diagnostic)] -#[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")] -#[help( - "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" -)] -#[note( - "`{$flag_name_prefixed}={$local_value}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`" -)] -#[help( - "set `{$flag_name_prefixed}={$extern_value}` in this crate or `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`" -)] -#[help( - "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" -)] -pub(crate) struct IncompatibleTargetModifiers { - #[primary_span] - pub span: Span, - pub extern_crate: Symbol, - pub local_crate: Symbol, - pub flag_name: String, - pub flag_name_prefixed: String, - pub local_value: String, - pub extern_value: String, -} - -#[derive(Diagnostic)] -#[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")] -#[help( - "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" -)] -#[note( - "`{$flag_name_prefixed}` is unset in this crate which is incompatible with {$has_extern_value -> - [false] `{$flag_name_prefixed}` being set - *[other] `{$flag_name_prefixed}={$extern_value}` - } in dependency `{$extern_crate}`" -)] -#[help( - "set {$has_extern_value -> - [false] `{$flag_name_prefixed}` - *[other] `{$flag_name_prefixed}={$extern_value}` - } in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}`" -)] -#[help( - "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" -)] -pub(crate) struct IncompatibleTargetModifiersLMissed { - #[primary_span] - pub span: Span, - pub extern_crate: Symbol, - pub local_crate: Symbol, - pub flag_name: String, - pub flag_name_prefixed: String, - pub extern_value: String, - pub has_extern_value: bool, -} - -#[derive(Diagnostic)] -#[diag("mixing `{$flag_name_prefixed}` will cause an ABI mismatch in crate `{$local_crate}`")] -#[help( - "the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" -)] -#[note( - "{$has_local_value -> - [false] `{$flag_name_prefixed}` being set - *[other] `{$flag_name_prefixed}={$local_value}` - } in this crate is incompatible with `{$flag_name_prefixed}` being unset in dependency `{$extern_crate}`" -)] -#[help( - "unset `{$flag_name_prefixed}` in this crate or set {$has_local_value -> - [false] `{$flag_name_prefixed}` - *[other] `{$flag_name_prefixed}={$local_value}` - } in `{$extern_crate}`" -)] -#[help( - "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" -)] -pub(crate) struct IncompatibleTargetModifiersRMissed { - #[primary_span] - pub span: Span, - pub extern_crate: Symbol, - pub local_crate: Symbol, - pub flag_name: String, - pub flag_name_prefixed: String, - pub local_value: String, - pub has_local_value: bool, -} - -#[derive(Diagnostic)] -#[diag( - "unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`" -)] -pub(crate) struct UnknownTargetModifierUnsafeAllowed { - #[primary_span] - pub span: Span, - pub flag_name: String, -} - #[derive(Diagnostic)] #[diag( "found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`" diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index f4d3380594c9f..ef8b77191ca78 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -31,7 +31,6 @@ use rustc_middle::{bug, implement_ty_decoder}; use rustc_proc_macro::bridge::client::Client as ProcMacroClient; use rustc_serialize::opaque::MemDecoder; use rustc_serialize::{Decodable, Decoder}; -use rustc_session::config::TargetModifier; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; use rustc_span::def_id::ModId; use rustc_span::hygiene::HygieneDecodeContext; @@ -81,10 +80,6 @@ impl MetadataBlob { /// own crate numbers. pub(crate) type CrateNumMap = IndexVec; -/// Target modifiers - abi or exploit mitigations options that may cause unsoundness when mixed or -/// partially enabled. -pub(crate) type TargetModifiers = Vec; - /// The set of mitigations that cannot be partially enabled (see /// [RFC 3855](https://github.com/rust-lang/rfcs/pull/3855)), but are currently enabled for this /// crate. @@ -755,7 +750,6 @@ impl MetadataBlob { "lang_items".to_owned(), "features".to_owned(), "items".to_owned(), - "target_modifiers".to_owned(), ]; let ls_kinds = if ls_kinds.contains(&"all".to_owned()) { &all_ls_kinds } else { ls_kinds }; @@ -925,28 +919,11 @@ impl MetadataBlob { write!(out, "\n")?; } - "target_modifiers" => { - writeln!(out, "=Target modifiers=")?; - - for modifier in root.decode_target_modifiers(self) { - let extended = modifier.extend(); - - writeln!( - out, - "-{}{}={} [{}]", - extended.prefix, - extended.name, - modifier.value_name, - extended.tech_value, - )?; - } - } _ => { writeln!( out, - "unknown -Zls kind. allowed values are: all, root, lang_items, features, items, \ - target_modifiers" + "unknown -Zls kind. allowed values are: all, root, lang_items, features, items" )?; } } @@ -990,13 +967,6 @@ impl CrateRoot { self.crate_deps.decode(metadata) } - pub(crate) fn decode_target_modifiers<'a>( - &self, - metadata: &'a MetadataBlob, - ) -> impl ExactSizeIterator { - self.target_modifiers.decode(metadata) - } - pub(crate) fn decode_denied_partial_mitigations<'a>( &self, metadata: &'a MetadataBlob, @@ -2002,10 +1972,6 @@ impl CrateMetadata { self.cnum_map.iter().copied() } - pub(crate) fn target_modifiers(&self) -> TargetModifiers { - self.root.decode_target_modifiers(&self.blob).collect() - } - pub(crate) fn enabled_denied_partial_mitigations(&self) -> DeniedPartialMitigations { self.root.decode_denied_partial_mitigations(&self.blob).collect() } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index b32a23f53f8cc..b5cb2cac8cd60 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -27,7 +27,7 @@ use rustc_middle::ty::fast_reject::{self, TreatParams}; use rustc_middle::{bug, span_bug}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque}; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; -use rustc_session::config::{CrateType, OptLevel, TargetModifier}; +use rustc_session::config::{CrateType, OptLevel}; use rustc_span::def_id::CRATE_MOD_ID; use rustc_span::hygiene::HygieneEncodeContext; use rustc_span::{ @@ -719,7 +719,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { // Encode source_map. This needs to be done last, because encoding `Span`s tells us which // `SourceFiles` we actually need to encode. let source_map = stat!("source-map", || self.encode_source_map()); - let target_modifiers = stat!("target-modifiers", || self.encode_target_modifiers()); let denied_partial_mitigations = stat!("denied-partial-mitigations", || self .encode_enabled_denied_partial_mitigations()); @@ -765,7 +764,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { native_libraries, foreign_modules, source_map, - target_modifiers, denied_partial_mitigations, traits, impls, @@ -2113,12 +2111,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.lazy_array(deps.iter().map(|(_, dep)| dep)) } - fn encode_target_modifiers(&mut self) -> LazyArray { - empty_proc_macro!(self); - let tcx = self.tcx; - self.lazy_array(tcx.sess.opts.gather_target_modifiers()) - } - fn encode_enabled_denied_partial_mitigations(&mut self) -> LazyArray { empty_proc_macro!(self); let tcx = self.tcx; diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 064d906293ae8..f6316c6632a4e 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use std::num::NonZero; use decoder::LazyDecoder; -pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob, TargetModifiers}; +pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; use def_path_hash_map::DefPathHashMapRef; use encoder::EncodeContext; pub use encoder::{EncodedMetadata, encode_metadata, rendered_const}; @@ -37,8 +37,8 @@ use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util::Providers; use rustc_serialize::opaque::FileEncoder; +use rustc_session::config::SymbolManglingVersion; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; -use rustc_session::config::{SymbolManglingVersion, TargetModifier}; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextKey}; use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Ident, Span, Symbol}; @@ -293,7 +293,6 @@ pub(crate) struct CrateRoot { def_path_hash_map: LazyValue>, source_map: LazyTable>>, - target_modifiers: LazyArray, denied_partial_mitigations: LazyArray, compiler_builtins: bool, diff --git a/compiler/rustc_metadata/src/rmeta/parameterized.rs b/compiler/rustc_metadata/src/rmeta/parameterized.rs index f19737bb936be..894077f78413f 100644 --- a/compiler/rustc_metadata/src/rmeta/parameterized.rs +++ b/compiler/rustc_metadata/src/rmeta/parameterized.rs @@ -133,7 +133,6 @@ trivially_parameterized_over_tcx! { rustc_middle::ty::Visibility, rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_middle::ty::fast_reject::SimplifiedType, - rustc_session::config::TargetModifier, rustc_session::config::mitigation_coverage::DeniedPartialMitigation, rustc_span::ExpnData, rustc_span::ExpnHash, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0303081e2c627..459f5c824f18d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1480,7 +1480,6 @@ impl Default for Options { color: ColorConfig::Auto, logical_env: FxIndexMap::default(), verbose: false, - target_modifiers: BTreeMap::default(), mitigation_coverage_map: Default::default(), jobs: Jobs { frontend: None, backend: None, linker: LinkerJobs::Default }, } @@ -2884,10 +2883,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M // -Zretpoline-external-thunk also requires -Zretpoline if unstable_opts.retpoline_external_thunk { unstable_opts.retpoline = true; - collected_options.target_modifiers.insert( - OptionsTargetModifiers::UnstableOptions(UnstableOptionsTargetModifiers::Retpoline), - "true".to_string(), - ); } let cg = cg; @@ -3055,7 +3050,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M color, logical_env, verbose, - target_modifiers: collected_options.target_modifiers, mitigation_coverage_map: collected_options.mitigations, jobs, } diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index a2f6f7b39fe91..ed9a71f16d508 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -5,7 +5,6 @@ #![feature(default_field_values)] #![feature(iter_intersperse)] #![feature(macro_derive)] -#![feature(macro_metavar_expr)] #![feature(option_into_flat_iter)] #![feature(rustc_attrs)] // To generate CodegenOptionsTargetModifiers and UnstableOptionsTargetModifiers enums diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 20d1ff55eab6e..3861442948196 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -12,7 +12,6 @@ use rustc_data_structures::stable_hash::StableHasher; use rustc_errors::{ColorConfig, TerminalUrl}; use rustc_feature::UnstableFeatures; use rustc_hashes::Hash64; -use rustc_macros::{BlobDecodable, Encodable}; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm}; @@ -25,7 +24,7 @@ use rustc_target::spec::{ use crate::config::*; use crate::search_paths::SearchPath; use crate::utils::NativeLib; -use crate::{EarlyDiagCtxt, Session, lint}; +use crate::{EarlyDiagCtxt, lint}; macro_rules! insert { ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => { @@ -63,141 +62,8 @@ macro_rules! hash_substruct { }}; } -/// Extended target modifier info. -/// For example, when external target modifier is '-Zregparm=2': -/// Target modifier enum value + user value ('2') from external crate -/// is converted into description: prefix ('Z'), name ('regparm'), tech value ('Some(2)'). -pub struct ExtendedTargetModifierInfo { - /// Flag prefix (usually, 'C' for codegen flags or 'Z' for unstable flags) - pub prefix: String, - /// Flag name - pub name: String, - /// Flag parsed technical value - pub tech_value: String, -} - -/// A recorded -Zopt_name=opt_value (or -Copt_name=opt_value) -/// which alter the ABI or effectiveness of exploit mitigations. -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, BlobDecodable)] -pub struct TargetModifier { - /// Option enum value - pub opt: OptionsTargetModifiers, - /// User-provided option value (before parsing) - pub value_name: String, -} - pub mod mitigation_coverage; -mod target_modifier_consistency_check { - use super::*; - pub(super) fn sanitizer(l: &TargetModifier, r: Option<&TargetModifier>) -> bool { - let mut lparsed: SanitizerSet = Default::default(); - let lval = if l.value_name.is_empty() { None } else { Some(l.value_name.as_str()) }; - parse::parse_sanitizers(&mut lparsed, lval); - - let mut rparsed: SanitizerSet = Default::default(); - let rval = r.filter(|v| !v.value_name.is_empty()).map(|v| v.value_name.as_str()); - parse::parse_sanitizers(&mut rparsed, rval); - - // Some sanitizers need to be target modifiers, and some do not. - // For now, we should mark all sanitizers as target modifiers except for these: - // AddressSanitizer, LeakSanitizer - let tmod_sanitizers = SanitizerSet::MEMORY - | SanitizerSet::THREAD - | SanitizerSet::HWADDRESS - | SanitizerSet::CFI - | SanitizerSet::MEMTAG - | SanitizerSet::SHADOWCALLSTACK - | SanitizerSet::KCFI - | SanitizerSet::KERNELADDRESS - | SanitizerSet::KERNELHWADDRESS - | SanitizerSet::SAFESTACK - | SanitizerSet::DATAFLOW; - - lparsed & tmod_sanitizers == rparsed & tmod_sanitizers - } - pub(super) fn sanitizer_cfi_normalize_integers( - sess: &Session, - l: &TargetModifier, - r: Option<&TargetModifier>, - ) -> bool { - // For kCFI, the helper flag -Zsanitizer-cfi-normalize-integers should also be a target modifier - if sess.sanitizers().contains(SanitizerSet::KCFI) { - if let Some(r) = r { - return l.extend().tech_value == r.extend().tech_value; - } else { - return false; - } - } - true - } - pub(super) fn target_cpu( - sess: &Session, - l: &TargetModifier, - r: Option<&TargetModifier>, - ) -> bool { - if !sess.target.requires_consistent_cpu { - return true; - } - let l_tech_value = l.extend().tech_value; - let r_tech_value = match r { - Some(r) => r.extend().tech_value, - // If only one of the two compared crates specifies the CPU - // explicitly we compare against the target's default CPU. - None => { - // We reuse the same parsing logic. - CodegenOptionsTargetModifiers::TargetCpu - .reparse(sess.target.cpu.as_ref()) - .tech_value - } - }; - l_tech_value == r_tech_value - } -} - -impl TargetModifier { - pub fn extend(&self) -> ExtendedTargetModifierInfo { - self.opt.reparse(&self.value_name) - } - // Custom consistency check for target modifiers (or default `l.tech_value == r.tech_value`) - // When other is None, consistency with default value is checked - pub fn consistent(&self, sess: &Session, other: Option<&TargetModifier>) -> bool { - assert!(other.is_none() || self.opt == other.unwrap().opt); - match self.opt { - OptionsTargetModifiers::UnstableOptions(unstable) => match unstable { - UnstableOptionsTargetModifiers::Sanitizer => { - return target_modifier_consistency_check::sanitizer(self, other); - } - UnstableOptionsTargetModifiers::SanitizerCfiNormalizeIntegers => { - return target_modifier_consistency_check::sanitizer_cfi_normalize_integers( - sess, self, other, - ); - } - _ => {} - }, - OptionsTargetModifiers::CodegenOptions(codegen) => match codegen { - CodegenOptionsTargetModifiers::TargetCpu => { - return target_modifier_consistency_check::target_cpu(sess, self, other); - } - }, - }; - match other { - Some(other) => self.extend().tech_value == other.extend().tech_value, - None => false, - } - } -} - -fn tmod_push_impl( - opt: OptionsTargetModifiers, - tmod_vals: &BTreeMap, - tmods: &mut Vec, -) { - if let Some(v) = tmod_vals.get(&opt) { - tmods.push(TargetModifier { opt, value_name: v.clone() }) - } -} - macro_rules! top_level_options { ( $(#[$top_level_attr:meta])* @@ -206,45 +72,10 @@ macro_rules! top_level_options { $(#[$attr:meta])* $opt:ident : $t:ty [$dep_tracking_marker:ident] - $( { TARGET_MODIFIER: $tmod_variant:ident($tmod_enum:ident) } )? , )* } ) => { - #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, BlobDecodable)] - pub enum OptionsTargetModifiers { - $( - $( - $tmod_variant($tmod_enum), - )? - )* - } - - impl OptionsTargetModifiers { - pub fn reparse(&self, user_value: &str) -> ExtendedTargetModifierInfo { - match self { - $( - $( - Self::$tmod_variant(v) => v.reparse(user_value), - )? - )* - #[allow(unreachable_patterns)] - _ => panic!("unknown target modifier option: {self:?}"), - } - } - - pub fn is_target_modifier(flag_name: &str) -> bool { - $( - $( - if $tmod_enum::is_target_modifier(flag_name) { - return true - } - )? - )* - false - } - } - #[derive(Clone)] $(#[$top_level_attr])* pub struct Options { @@ -252,7 +83,6 @@ macro_rules! top_level_options { $(#[$attr])* pub $opt: $t, )* - pub target_modifiers: BTreeMap, pub mitigation_coverage_map: mitigation_coverage::MitigationCoverageMap, } @@ -287,19 +117,6 @@ macro_rules! top_level_options { )* hasher.finish() } - - pub fn gather_target_modifiers(&self) -> Vec { - let mut mods = Vec::::new(); - $( - $( - // Only expand for flags that have `TARGET_MODIFIER`. - ${ignore($tmod_enum)} - self.$opt.gather_target_modifiers(&mut mods, &self.target_modifiers); - )? - )* - mods.sort_by(|a, b| a.opt.cmp(&b.opt)); - mods - } } } } @@ -361,9 +178,9 @@ top_level_options!( /// directory to store intermediate results. incremental: Option [UNTRACKED], - unstable_opts: UnstableOptions [SUBSTRUCT] { TARGET_MODIFIER: UnstableOptions(UnstableOptionsTargetModifiers) }, + unstable_opts: UnstableOptions [SUBSTRUCT], prints: Vec [UNTRACKED], - cg: CodegenOptions [SUBSTRUCT] { TARGET_MODIFIER: CodegenOptions(CodegenOptionsTargetModifiers) }, + cg: CodegenOptions [SUBSTRUCT], externs: Externs [UNTRACKED], crate_name: Option [TRACKED], /// Indicates how the compiler should treat unstable features. @@ -441,7 +258,6 @@ top_level_options!( #[derive(Default)] pub struct CollectedOptions { - pub target_modifiers: BTreeMap, pub mitigations: mitigation_coverage::MitigationCoverageMap, } @@ -491,7 +307,6 @@ macro_rules! setter_for { macro_rules! options { ( $struct_name:ident, - $tmod_enum:ident, $stat:ident, $optmod:ident, $prefix:expr, @@ -503,7 +318,6 @@ macro_rules! options { $init:expr, $parse:ident, [$dep_tracking_marker:ident] - $( { TARGET_MODIFIER: $tmod_variant:ident } )? $( { MITIGATION: $mitigation_variant:ident } )? , $desc:literal @@ -520,50 +334,6 @@ macro_rules! options { )* } - #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, BlobDecodable)] - pub enum $tmod_enum { - $( - $( $tmod_variant, )? - )* - } - - impl $tmod_enum { - pub fn reparse(&self, _user_value: &str) -> ExtendedTargetModifierInfo { - match self { - $( - $( - Self::$tmod_variant => { - let mut parsed: $t = Default::default(); - let val = if _user_value.is_empty() { None } else { Some(_user_value) }; - parse::$parse(&mut parsed, val); - ExtendedTargetModifierInfo { - prefix: $prefix.to_string(), - name: stringify!($opt).to_string().replace('_', "-"), - tech_value: format!("{:?}", parsed), - } - } - )? - )* - - #[allow(unreachable_patterns)] - _ => panic!("unknown target modifier option: {:?}", *self) - } - } - - pub fn is_target_modifier(flag_name: &str) -> bool { - match flag_name.replace('-', "_").as_str() { - $( - $( - // Only expand for flags that have `TARGET_MODIFIER`. - ${ignore($tmod_variant)} - stringify!($opt) => true, - )? - )* - _ => false, - } - } - } - impl Default for $struct_name { fn default() -> $struct_name { $struct_name { @@ -578,9 +348,9 @@ macro_rules! options { pub fn build( early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches, - target_modifiers: &mut CollectedOptions, + collected_options: &mut CollectedOptions, ) -> $struct_name { - build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname) + build_options(early_dcx, matches, collected_options, $stat, $prefix, $outputname) } fn dep_tracking_hash( @@ -607,24 +377,6 @@ macro_rules! options { ); hasher.finish() } - - pub fn gather_target_modifiers( - &self, - _mods: &mut Vec, - _tmod_vals: &BTreeMap, - ) { - $( - $( - if self.$opt != $init { - tmod_push_impl( - OptionsTargetModifiers::$struct_name($tmod_enum::$tmod_variant), - _tmod_vals, - _mods, - ); - } - )? - )* - } } pub const $stat: OptionDescrs<$struct_name> = &[ @@ -635,9 +387,6 @@ macro_rules! options { type_desc: desc::$parse, desc: $desc, removed: None $( .or(Some(RemovedOption::$removed)) )?, - tmod: None $( .or(Some( - OptionsTargetModifiers::$struct_name($tmod_enum::$tmod_variant) - )))?, mitigation: None $( .or(Some( mitigation_coverage::DeniedPartialMitigationKind::$mitigation_variant )))?, @@ -693,7 +442,6 @@ pub struct OptionDesc { // description for option from options table desc: &'static str, removed: Option, - tmod: Option, mitigation: Option, } @@ -724,7 +472,7 @@ fn build_options( let option_to_lookup = key.replace('-', "_"); match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) { - Some(OptionDesc { name: _, setter, type_desc, desc, removed, tmod, mitigation }) => { + Some(OptionDesc { name: _, setter, type_desc, desc, removed, mitigation }) => { if let Some(removed) = removed { // deprecation works for prefixed options only assert!(!prefix.is_empty()); @@ -751,28 +499,6 @@ fn build_options( ), } } - if let Some(tmod) = *tmod { - let v = value.map_or(String::new(), ToOwned::to_owned); - - // Accumulate all the -Zsanitizer flags into a single target modifier. - match tmod { - OptionsTargetModifiers::UnstableOptions( - UnstableOptionsTargetModifiers::Sanitizer, - ) => { - collected_options - .target_modifiers - .entry(tmod) - .and_modify(|existing| { - existing.push(','); - existing.push_str(&v); - }) - .or_insert(v); - } - _ => { - collected_options.target_modifiers.insert(tmod, v); - } - } - } if let Some(mitigation) = mitigation { collected_options.mitigations.reset_mitigation(*mitigation, index); } @@ -2191,7 +1917,7 @@ pub mod parse { } options! { - CodegenOptions, CodegenOptionsTargetModifiers, CG_OPTIONS, cgopts, "C", "codegen", + CodegenOptions, CG_OPTIONS, cgopts, "C", "codegen", // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs @@ -2324,7 +2050,7 @@ options! { symbol_mangling_version: Option = (None, parse_symbol_mangling_version, [TRACKED], "which mangling version to use for symbol names ('legacy', 'v0' (default), or 'hashed')"), - target_cpu: Option = (None, parse_opt_string, [TRACKED] { TARGET_MODIFIER: TargetCpu }, + target_cpu: Option = (None, parse_opt_string, [TRACKED], "select target processor (`rustc --print target-cpus` for details)"), target_feature: String = (String::new(), parse_target_feature, [TRACKED], "target specific attributes. (`rustc --print target-features` for details). \ @@ -2339,7 +2065,7 @@ options! { } options! { - UnstableOptions, UnstableOptionsTargetModifiers, Z_OPTIONS, dbopts, "Z", "unstable", + UnstableOptions, Z_OPTIONS, dbopts, "Z", "unstable", // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs @@ -2391,7 +2117,7 @@ options! { box_noalias: bool = (true, parse_bool, [TRACKED], "emit noalias metadata for box (default: yes)"), #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] - branch_protection: Option = (None, parse_branch_protection, [TRACKED] { TARGET_MODIFIER: BranchProtection }, + branch_protection: Option = (None, parse_branch_protection, [TRACKED], "set options for branch target identification and pointer authentication on AArch64"), build_sdylib_interface: bool = (false, parse_bool, [UNTRACKED], "whether the stable interface is being built"), @@ -2498,7 +2224,7 @@ options! { fewer_names: Option = (None, parse_opt_bool, [TRACKED], "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \ (default: no)"), - fixed_x18: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: FixedX18 }, + fixed_x18: bool = (false, parse_bool, [TRACKED], "make the x18 register reserved on AArch64 (default: no)"), flatten_format_args: bool = (true, parse_bool, [TRACKED], "flatten nested format_args!() and literals into a simplified format_args!() call \ @@ -2549,7 +2275,7 @@ options! { - hashes of green query instances - hash collisions of query keys - hash collisions when creating dep-nodes"), - indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: IndirectBranchCsPrefix }, + indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED], "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), inline_llvm: bool = (true, parse_bool, [TRACKED], "enable LLVM inlining (default: yes)"), @@ -2605,7 +2331,7 @@ options! { "a list of module flags to pass to LLVM (space separated)"), llvm_plugins: Vec = (Vec::new(), parse_list, [TRACKED], "a list LLVM plugins to enable (space separated)"), - llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED] { TARGET_MODIFIER: LlvmTargetFeature }, + llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED], "enable/disable LLVM-level target features. \ This feature is unsafe and can cause ABI issues and compiler crashes, \ because LLVM does not support all target feature combinations."), @@ -2720,8 +2446,7 @@ options! { pointer_authentication: Vec<(PointerAuthOption, bool)> = ( Vec::new(), parse_pointer_authentication_list_with_polarity, - [TRACKED] - { TARGET_MODIFIER: PointerAuthentication }, + [TRACKED], "A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options: `aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch `auth-traps` - trap immediately on pointer authentication failure @@ -2774,10 +2499,10 @@ options! { "enable queries of the dependency graph for regression testing (default: no)"), randomize_layout: bool = (false, parse_bool, [TRACKED], "randomize the layout of types (default: no)"), - reg_struct_return: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: RegStructReturn }, + reg_struct_return: bool = (false, parse_bool, [TRACKED], "On x86-32 targets, it overrides the default ABI to return small structs in registers. It is UNSOUND to link together crates that use different values for this flag!"), - regparm: Option = (None, parse_opt_number, [TRACKED] { TARGET_MODIFIER: Regparm }, + regparm: Option = (None, parse_opt_number, [TRACKED], "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ in registers EAX, EDX, and ECX instead of on the stack for\ \"C\", \"cdecl\", and \"stdcall\" fn.\ @@ -2791,19 +2516,19 @@ options! { written to standard error output)"), renormalize_rigid_aliases: bool = (false, parse_bool, [TRACKED], "do not skip rigid aliases in normalization for internal debugging"), - retpoline: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: Retpoline }, + retpoline: bool = (false, parse_bool, [TRACKED], "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), - retpoline_external_thunk: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: RetpolineExternalThunk }, + retpoline_external_thunk: bool = (false, parse_bool, [TRACKED], "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ target features (default: no)"), #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] - sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED] { TARGET_MODIFIER: Sanitizer }, + sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], "use a sanitizer"), sanitizer_cfi_canonical_jump_tables: Option = (Some(true), parse_opt_bool, [TRACKED], "enable canonical jump tables (default: yes)"), sanitizer_cfi_generalize_pointers: Option = (None, parse_opt_bool, [TRACKED], "enable generalizing pointer types (default: no)"), - sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: SanitizerCfiNormalizeIntegers }, + sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED], "enable normalizing integer types (default: no)"), sanitizer_cfi_diag: Option = (None, parse_opt_bool, [TRACKED], "enable CFI diagnostics (default: no)"), diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 1584cacff688e..d683dedd2d369 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -9,8 +9,8 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::DiagCtxtHandle; use rustc_session::config::{ self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns, - OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, - nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple, + OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, nightly_options, + parse_crate_types_from_list, parse_externs, parse_target_triple, }; use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; @@ -166,9 +166,6 @@ pub(crate) struct Options { /// Arguments to be used when compiling doctests. pub(crate) doctest_build_args: Vec, - - /// Target modifiers. - pub(crate) target_modifiers: BTreeMap, } impl fmt::Debug for Options { @@ -961,7 +958,6 @@ impl Options { scrape_examples_options, unstable_features, doctest_build_args, - target_modifiers: collected_options.target_modifiers, }; let render_options = RenderOptions { output, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index af1024580c544..cb6766fecaa5d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -227,7 +227,6 @@ pub(crate) fn create_config( scrape_examples_options, remap_path_prefix, remap_path_scope, - target_modifiers, .. }: RustdocOptions, render_options: &RenderOptions, @@ -293,7 +292,6 @@ pub(crate) fn create_config( } else { OutputTypes::new(&[]) }, - target_modifiers, ..Options::default() }; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 7ba409626ea89..7b0bfabf49ba6 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -174,7 +174,6 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions remap_path_scope: options.remap_path_scope.clone(), unstable_opts: options.unstable_opts.clone(), error_format: options.error_format.clone(), - target_modifiers: options.target_modifiers.clone(), ..config::Options::default() }; From 7e8cb32ec1460cd83e9b5c60f52ae259a23249a6 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 25 Jun 2026 13:46:08 +0000 Subject: [PATCH 02/29] sess: rename some `options!` metavars A small refactoring just to give each of these meta-variables better names. --- compiler/rustc_session/src/options.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3861442948196..1b8e104312e30 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -306,11 +306,11 @@ macro_rules! setter_for { /// hand-written parsers for parsing specific types of values in this module. macro_rules! options { ( - $struct_name:ident, - $stat:ident, - $optmod:ident, - $prefix:expr, - $outputname:expr, + $struct_name:ident, // e.g. `UnstableOptions` + $opt_descs_var:ident, // e.g. `Z_OPTIONS` + $opt_mod_name:ident, // e.g. `dbopts` + $prefix:expr, // e.g. `-Z` + $group_name:expr, // e.g. "unstable" $( $(#[$attr:meta])* @@ -350,7 +350,8 @@ macro_rules! options { matches: &getopts::Matches, collected_options: &mut CollectedOptions, ) -> $struct_name { - build_options(early_dcx, matches, collected_options, $stat, $prefix, $outputname) + build_options( + early_dcx, matches, collected_options, $opt_descs_var, $prefix, $group_name) } fn dep_tracking_hash( @@ -379,11 +380,11 @@ macro_rules! options { } } - pub const $stat: OptionDescrs<$struct_name> = &[ + pub const $opt_descs_var: OptionDescrs<$struct_name> = &[ $( OptionDesc { name: stringify!($opt), - setter: $optmod::$opt, + setter: $opt_mod_name::$opt, type_desc: desc::$parse, desc: $desc, removed: None $( .or(Some(RemovedOption::$removed)) )?, @@ -394,7 +395,7 @@ macro_rules! options { )* ]; - mod $optmod { + mod $opt_mod_name { $( setter_for!($opt, $struct_name, $parse); )* From 58c754d1c7a8e888495d07ba7fb7116f3b4962d1 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 26 Jun 2026 10:53:53 +0000 Subject: [PATCH 03/29] sess: option metadata Reporting good target modifier mismatch errors will require at least knowing whether a option was set by the user explicitly rather than just having its default value. This small addition to the infrastructure enables that to be tracked. It is not persisted into the cross-crate metadata, it will only be required in the local crate. --- compiler/rustc_session/src/config.rs | 2 ++ compiler/rustc_session/src/options.rs | 48 ++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 459f5c824f18d..d63c7e778a462 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1482,6 +1482,7 @@ impl Default for Options { verbose: false, mitigation_coverage_map: Default::default(), jobs: Jobs { frontend: None, backend: None, linker: LinkerJobs::Default }, + metadata: Default::default(), } } } @@ -3052,6 +3053,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M verbose, mitigation_coverage_map: collected_options.mitigations, jobs, + metadata: collected_options.metadata, } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 1b8e104312e30..8f675dc56f0b4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -64,6 +64,19 @@ macro_rules! hash_substruct { pub mod mitigation_coverage; +/// Metadata associated with an option +#[derive(Clone, Default)] +pub struct OptionMetadata { + /// Was this option set by the user? + is_set: bool, +} + +#[derive(Clone, Default)] +pub struct OptionsMetadata { + codegen: CodegenOptionsMetadata, + unstable: UnstableOptionsMetadata, +} + macro_rules! top_level_options { ( $(#[$top_level_attr:meta])* @@ -84,6 +97,7 @@ macro_rules! top_level_options { pub $opt: $t, )* pub mitigation_coverage_map: mitigation_coverage::MitigationCoverageMap, + pub metadata: OptionsMetadata, } impl Options { @@ -259,12 +273,13 @@ top_level_options!( #[derive(Default)] pub struct CollectedOptions { pub mitigations: mitigation_coverage::MitigationCoverageMap, + pub metadata: OptionsMetadata, } macro_rules! setter_for { // the allow/deny-mitigations options use collected/index instead of the cg, since they // work across option groups - (allow_partial_mitigations, $struct_name:ident, $parse:ident) => { + (allow_partial_mitigations, $struct_name:ident, $group_name:ident, $parse:ident) => { pub(super) fn allow_partial_mitigations( _cg: &mut super::$struct_name, collected: &mut super::CollectedOptions, @@ -274,7 +289,7 @@ macro_rules! setter_for { collected.mitigations.handle_allowdeny_mitigation_option(v, index, true) } }; - (deny_partial_mitigations, $struct_name:ident, $parse:ident) => { + (deny_partial_mitigations, $struct_name:ident, $group_name:ident, $parse:ident) => { pub(super) fn deny_partial_mitigations( _cg: &mut super::$struct_name, collected: &mut super::CollectedOptions, @@ -284,13 +299,14 @@ macro_rules! setter_for { collected.mitigations.handle_allowdeny_mitigation_option(v, index, false) } }; - ($opt:ident, $struct_name:ident, $parse:ident) => { + ($opt:ident, $struct_name:ident, $group_name:ident, $parse:ident) => { pub(super) fn $opt( cg: &mut super::$struct_name, - _collected: &mut super::CollectedOptions, + collected: &mut super::CollectedOptions, v: Option<&str>, _index: usize, ) -> bool { + collected.metadata.$group_name.$opt.is_set = v.is_some(); super::parse::$parse(&mut redirect_field!(cg.$opt), v) } }; @@ -307,10 +323,11 @@ macro_rules! setter_for { macro_rules! options { ( $struct_name:ident, // e.g. `UnstableOptions` + $metadata_name: ident, // e.g. `UnstableOptionsMetadata` $opt_descs_var:ident, // e.g. `Z_OPTIONS` $opt_mod_name:ident, // e.g. `dbopts` $prefix:expr, // e.g. `-Z` - $group_name:expr, // e.g. "unstable" + $group_name:ident, // e.g. `unstable` $( $(#[$attr:meta])* @@ -334,6 +351,13 @@ macro_rules! options { )* } + #[derive(Clone, Default)] + pub struct $metadata_name { + $( + pub $opt: OptionMetadata, + )* + } + impl Default for $struct_name { fn default() -> $struct_name { $struct_name { @@ -351,7 +375,13 @@ macro_rules! options { collected_options: &mut CollectedOptions, ) -> $struct_name { build_options( - early_dcx, matches, collected_options, $opt_descs_var, $prefix, $group_name) + early_dcx, + matches, + collected_options, + $opt_descs_var, + $prefix, + stringify!($group_name) + ) } fn dep_tracking_hash( @@ -397,7 +427,7 @@ macro_rules! options { mod $opt_mod_name { $( - setter_for!($opt, $struct_name, $parse); + setter_for!($opt, $struct_name, $group_name, $parse); )* } } @@ -1918,7 +1948,7 @@ pub mod parse { } options! { - CodegenOptions, CG_OPTIONS, cgopts, "C", "codegen", + CodegenOptions, CodegenOptionsMetadata, CG_OPTIONS, cgopts, "C", codegen, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs @@ -2066,7 +2096,7 @@ options! { } options! { - UnstableOptions, Z_OPTIONS, dbopts, "Z", "unstable", + UnstableOptions, UnstableOptionsMetadata, Z_OPTIONS, dbopts, "Z", unstable, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs From 5d29b486a0b87b3b9f1e649ac94e058bb736f644 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 26 Jun 2026 11:58:46 +0000 Subject: [PATCH 04/29] sess: re-implement target modifiers Introduces a new implementation of target modifiers under the `-T` prefix, leveraging that all of the options are in the one struct so that the whole type can just be encoded or decoded to keep track of the values set in downstream crates. The term "target modifiers" is leaked, not just "target flags" because `--target` is already used (unsurprisingly!). Also introduces a new trait to control printing of the values of target modifier options in the target modifier diagnostics. --- compiler/rustc_driver_impl/src/lib.rs | 1 + compiler/rustc_interface/src/tests.rs | 20 +++ compiler/rustc_metadata/src/creader.rs | 24 +++ compiler/rustc_metadata/src/diagnostics.rs | 10 ++ compiler/rustc_metadata/src/rmeta/decoder.rs | 12 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 1 + compiler/rustc_metadata/src/rmeta/mod.rs | 3 +- compiler/rustc_session/src/config.rs | 12 ++ compiler/rustc_session/src/diagnostics.rs | 49 ++++++ compiler/rustc_session/src/options.rs | 149 ++++++++++++++++++ src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/target-options/index.md | 5 + src/librustdoc/config.rs | 16 +- src/librustdoc/core.rs | 2 + src/librustdoc/doctest.rs | 4 + src/librustdoc/lib.rs | 8 + tests/run-make/rustc-help/help-v.diff | 5 +- tests/run-make/rustc-help/help-v.stdout | 3 + tests/run-make/rustc-help/help.stdout | 3 + .../default-output/output-default.stdout | 2 + 20 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 src/doc/rustc/src/target-options/index.md diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index e2c9f3f909b8b..f4ff132372566 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -940,6 +940,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) { safe_println!( "{options}{at_path}\nAdditional help: -C help Print codegen options + -T help Print target modifier options -W help \ Print 'lint' options and default settings{nightly}{verbose}\n", options = options.usage(message), diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 548ee3f4b8e7b..3a681a0a30b4e 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -693,6 +693,26 @@ fn test_top_level_options_tracked_no_crate() { // tidy-alphabetical-end } +#[test] +fn test_target_options_tracking_hash() { + let reference = Options::default(); + let mut opts; + + macro_rules! tracked { + ($name: ident, $non_default_value: expr) => { + opts = reference.clone(); + assert_ne!(opts.target_opts.$name, $non_default_value); + opts.target_opts.$name = $non_default_value; + assert_different_hash(&reference, &opts); + }; + } + + // Make sure that changing a [TRACKED] option changes the hash. + // tidy-alphabetical-start + tracked!(fixed_x18, true); + // tidy-alphabetical-end +} + #[test] fn test_unstable_options_tracking_hash() { let reference = Options::default(); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index b5545a0642d32..3407da9a6709f 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -338,10 +338,34 @@ impl CStore { } pub fn report_session_incompatibilities(&self, tcx: TyCtxt<'_>, krate: &Crate) { + self.report_incompatible_target_modifiers(tcx, krate); self.report_incompatible_partial_mitigations(tcx, krate); self.report_incompatible_async_drop_feature(tcx, krate); } + pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>, krate: &Crate) { + for flag_name in &tcx.sess.opts.cg.unsafe_allow_abi_mismatch { + if !rustc_session::config::TargetOptions::is_target_modifier(flag_name) { + tcx.dcx().emit_err(diagnostics::UnknownTargetModifierUnsafeAllowed { + span: krate.spans.inner_span.shrink_to_lo(), + flag_name: flag_name.clone(), + }); + } + } + for (_, data) in self.iter_crate_data() { + if data.is_proc_macro_crate() { + continue; + } + tcx.sess.opts.target_opts.report_mismatched_flags_with_dep( + tcx.sess, + krate.spans.inner_span.shrink_to_lo(), + tcx.crate_name(LOCAL_CRATE), + data.target_opts(), + data.name(), + ); + } + } + pub fn report_incompatible_partial_mitigations(&self, tcx: TyCtxt<'_>, krate: &Crate) { let my_mitigations = tcx.sess.gather_enabled_denied_partial_mitigations(); let mut my_mitigations: BTreeMap<_, _> = diff --git a/compiler/rustc_metadata/src/diagnostics.rs b/compiler/rustc_metadata/src/diagnostics.rs index 1ce564861f2b9..73c798350d090 100644 --- a/compiler/rustc_metadata/src/diagnostics.rs +++ b/compiler/rustc_metadata/src/diagnostics.rs @@ -535,6 +535,16 @@ pub(crate) struct WasmCAbi { pub span: Span, } +#[derive(Diagnostic)] +#[diag( + "unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`" +)] +pub(crate) struct UnknownTargetModifierUnsafeAllowed { + #[primary_span] + pub span: Span, + pub flag_name: String, +} + #[derive(Diagnostic)] #[diag( "found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`" diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index ef8b77191ca78..d2fea11dc4027 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -750,6 +750,7 @@ impl MetadataBlob { "lang_items".to_owned(), "features".to_owned(), "items".to_owned(), + "target_modifiers".to_owned(), ]; let ls_kinds = if ls_kinds.contains(&"all".to_owned()) { &all_ls_kinds } else { ls_kinds }; @@ -919,11 +920,16 @@ impl MetadataBlob { write!(out, "\n")?; } + "target_modifiers" => { + writeln!(out, "=Target modifiers=")?; + writeln!(out, "{}", root.target_options.ls())?; + } _ => { writeln!( out, - "unknown -Zls kind. allowed values are: all, root, lang_items, features, items" + "unknown -Zls kind. allowed values are: all, root, lang_items, features, items, \ + target_modifiers" )?; } } @@ -1976,6 +1982,10 @@ impl CrateMetadata { self.root.decode_denied_partial_mitigations(&self.blob).collect() } + pub(crate) fn target_opts(&self) -> &TargetOptions { + &self.root.target_options + } + /// Keep `new_extern_crate` if it looks better in diagnostics pub(crate) fn update_extern_crate_diagnostics( &mut self, diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index b5cb2cac8cd60..a3f882461b536 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -751,6 +751,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { panic_runtime: find_attr!(attrs, PanicRuntime), profiler_runtime: find_attr!(attrs, ProfilerRuntime), symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(), + target_options: tcx.sess.opts.target_opts.clone(), crate_deps, dylib_dependency_formats, diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index f6316c6632a4e..95129d49122cb 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -37,8 +37,8 @@ use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util::Providers; use rustc_serialize::opaque::FileEncoder; -use rustc_session::config::SymbolManglingVersion; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; +use rustc_session::config::{SymbolManglingVersion, TargetOptions}; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextKey}; use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Ident, Span, Symbol}; @@ -294,6 +294,7 @@ pub(crate) struct CrateRoot { source_map: LazyTable>>, denied_partial_mitigations: LazyArray, + target_options: TargetOptions, compiler_builtins: bool, needs_allocator: bool, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d63c7e778a462..936ad0238dcf7 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1426,6 +1426,7 @@ fn file_path_mapping( impl Default for Options { fn default() -> Options { + let target_opts = TargetOptions::default(); let unstable_opts = UnstableOptions::default(); // FIXME(Urgau): This is a hack that ideally shouldn't exist, but rustdoc @@ -1451,6 +1452,7 @@ impl Default for Options { target_triple: TargetTuple::from_tuple(host_tuple()), test: false, incremental: None, + target_opts, unstable_opts, prints: Vec::new(), cg: Default::default(), @@ -2041,6 +2043,14 @@ pub fn rustc_optgroups() -> Vec { "", ), opt(Stable, Multi, "C", "codegen", "Set a codegen option", "[=]"), + opt( + Stable, + Multi, + "T", + "target-modifier", + "Set a target modifier option", + "[=]", + ), opt(Stable, Flag, "V", "version", "Print version info and exit", ""), opt(Stable, Flag, "v", "verbose", "Use verbose output", ""), ]; @@ -2694,6 +2704,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let mut collected_options = Default::default(); + let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); // `-Zassumptions-on-binders` requires the next trait solver globally. Normalize after @@ -3022,6 +3033,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M target_triple, test, incremental, + target_opts, unstable_opts, prints, cg, diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index c229adf5aef4d..2d94185e44f16 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -721,3 +721,52 @@ pub(crate) struct NativeTargetCpuNotAllowed<'a> { pub(crate) target_triple: &'a TargetTuple, pub(crate) need_explicit_cpu: bool, } + +#[derive(Diagnostic)] +#[diag("mixing `-{$prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`")] +#[help( + "the `-{$prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" +)] +#[note( + "`-{$prefix}{$flag_name}={$local_value}` in this crate is incompatible with `-{$prefix}{$flag_name}={$extern_value}` in dependency `{$extern_crate}`" +)] +#[help( + "set `-{$prefix}{$flag_name}={$extern_value}` in this crate or `-{$prefix}{$flag_name}={$local_value}` in `{$extern_crate}`" +)] +#[help( + "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" +)] +pub(crate) struct IncompatibleFlags { + #[primary_span] + pub span: Span, + pub extern_crate: Symbol, + pub local_crate: Symbol, + pub prefix: String, + pub flag_name: String, + pub local_value: String, + pub extern_value: String, +} + +#[derive(Diagnostic)] +#[diag("mixing `-{$prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`")] +#[help( + "the `-{$prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" +)] +#[note( + "unset `-{$prefix}{$flag_name}` in this crate is incompatible with `-{$prefix}{$flag_name}={$extern_value}` in dependency `{$extern_crate}`" +)] +#[help( + "set `-{$prefix}{$flag_name}={$extern_value}` in this crate or unset `-{$prefix}{$flag_name}` in `{$extern_crate}`" +)] +#[help( + "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" +)] +pub(crate) struct IncompatibleFlagsUnsetLocally { + #[primary_span] + pub span: Span, + pub extern_crate: Symbol, + pub local_crate: Symbol, + pub prefix: String, + pub flag_name: String, + pub extern_value: String, +} diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8f675dc56f0b4..4da8a0074f44e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -12,6 +12,7 @@ use rustc_data_structures::stable_hash::StableHasher; use rustc_errors::{ColorConfig, TerminalUrl}; use rustc_feature::UnstableFeatures; use rustc_hashes::Hash64; +use rustc_macros::{BlobDecodable, Encodable}; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm}; @@ -74,6 +75,7 @@ pub struct OptionMetadata { #[derive(Clone, Default)] pub struct OptionsMetadata { codegen: CodegenOptionsMetadata, + target: TargetOptionsMetadata, unstable: UnstableOptionsMetadata, } @@ -192,6 +194,7 @@ top_level_options!( /// directory to store intermediate results. incremental: Option [UNTRACKED], + target_opts: TargetOptions [SUBSTRUCT], unstable_opts: UnstableOptions [SUBSTRUCT], prints: Vec [UNTRACKED], cg: CodegenOptions [SUBSTRUCT], @@ -322,6 +325,7 @@ macro_rules! setter_for { /// hand-written parsers for parsing specific types of values in this module. macro_rules! options { ( + $(#[$struct_attr:meta])* $struct_name:ident, // e.g. `UnstableOptions` $metadata_name: ident, // e.g. `UnstableOptionsMetadata` $opt_descs_var:ident, // e.g. `Z_OPTIONS` @@ -342,6 +346,7 @@ macro_rules! options { ), )* ) => { + $(#[$struct_attr])* #[derive(Clone)] #[rustc_lint_opt_ty] pub struct $struct_name { @@ -433,6 +438,137 @@ macro_rules! options { } } +trait TargetModifierOptionValue { + fn to_string_for_diag(&self) -> String; +} + +impl TargetModifierOptionValue for bool { + fn to_string_for_diag(&self) -> String { + self.to_string() + } +} + +impl TargetModifierOptionValue for u32 { + fn to_string_for_diag(&self) -> String { + self.to_string() + } +} + +impl TargetModifierOptionValue for Option { + fn to_string_for_diag(&self) -> String { + match self { + Some(v) => v.to_string_for_diag(), + None => "".to_string(), + } + } +} + +macro_rules! target_modifier_options { + ( + $struct_name:ident, // e.g. `UnstableOptions` + $metadata_name: ident, // e.g. `UnstableOptionsMetadata` + $opt_descs_var:ident, // e.g. `Z_OPTIONS` + $opt_mod_name:ident, // e.g. `dbopts` + $prefix:expr, // e.g. `-Z` + $group_name:ident, // e.g. `unstable` + + $( + $(#[$attr:meta])* + $opt:ident : $t:ty = ( + $init:expr, + $parse:ident, + [$dep_tracking_marker:ident], + $desc:literal + $(, removed: $removed:ident )? + ), + )* + ) => { + options! { + #[derive(Encodable, BlobDecodable)] + $struct_name, + $metadata_name, + $opt_descs_var, + $opt_mod_name, + $prefix, + $group_name, + + $( + $(#[$attr])* + $opt : $t = ( + $init, + $parse, + [$dep_tracking_marker], + $desc + $(, removed: $removed )? + ), + )* + } + + impl $struct_name { + pub fn ls(&self) -> String { + let mut out = Vec::new(); + $( + out.push(format!( + "-{prefix}{opt}={val} [{val:?}]", + prefix=$prefix, + opt=stringify!($opt).replace('_', "-"), + val=self.$opt.to_string_for_diag()) + ); + )* + out.join("\n") + } + + pub fn is_target_modifier(name: &str) -> bool { + let name = name.replace('-', "_"); + match name.as_str() { + $(stringify!($opt))|* => true, + _ => false, + } + } + + pub fn report_mismatched_flags_with_dep( + &self, + sess: &crate::Session, + span: rustc_span::Span, + local_crate: rustc_span::Symbol, + extern_opts: &Self, + extern_crate: rustc_span::Symbol + ) { + let allowed_flag_mismatches = &sess.opts.cg.unsafe_allow_abi_mismatch; + $( + let flag_name = stringify!($opt).replace('_', "-").to_string(); + let allowed = allowed_flag_mismatches.contains(&flag_name); + if !allowed && self.$opt != extern_opts.$opt { + if sess.opts.metadata.$group_name.$opt.is_set { + // If `self` set and not matching, `extern_opts` might have set `$opt` + // or might not, but the guidance is the same regardless + sess.dcx().emit_err(crate::diagnostics::IncompatibleFlags { + span, + local_crate, + extern_crate, + prefix: $prefix.to_string(), + flag_name, + local_value: self.$opt.to_string_for_diag(), + extern_value: extern_opts.$opt.to_string_for_diag(), + }); + } else { + // If `self` unset and not matching, assume `extern_opts` set `$opt` + sess.dcx().emit_err(crate::diagnostics::IncompatibleFlagsUnsetLocally { + span, + local_crate, + extern_crate, + prefix: $prefix.to_string(), + flag_name, + extern_value: extern_opts.$opt.to_string_for_diag(), + }); + } + } + )* + } + } + } +} + impl CodegenOptions { // JUSTIFICATION: defn of the suggested wrapper fn #[allow(rustc::bad_opt_access)] @@ -2095,6 +2231,19 @@ options! { // - src/doc/rustc/src/codegen-options/index.md } +target_modifier_options! { + TargetOptions, TargetOptionsMetadata, T_OPTIONS, topts, "T", target, + + // tidy-alphabetical-start + fixed_x18: bool = (false, parse_bool, [TRACKED], + "make the x18 register reserved on AArch64 (default: no)"), + // tidy-alphabetical-end + + // If you add a new option, please update: + // - compiler/rustc_interface/src/tests.rs + // - src/doc/rustc/src/target-options/index.md (for stable options) +} + options! { UnstableOptions, UnstableOptionsMetadata, Z_OPTIONS, dbopts, "Z", unstable, diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index bedfa65ac894d..255feffaec8bf 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -4,6 +4,7 @@ - [Command-line Arguments](command-line-arguments.md) - [Print Options](command-line-arguments/print-options.md) - [Codegen Options](codegen-options/index.md) + - [Target Options](target-options/index.md) - [Jobserver](jobserver.md) - [Lints](lints/index.md) - [Lint Levels](lints/levels.md) diff --git a/src/doc/rustc/src/target-options/index.md b/src/doc/rustc/src/target-options/index.md new file mode 100644 index 0000000000000..f2f63a01574a0 --- /dev/null +++ b/src/doc/rustc/src/target-options/index.md @@ -0,0 +1,5 @@ +# Target Options + +All of these options are passed to `rustc` via the `-T` flag, short for "target." You can see +a version of this list for your exact compiler by running `rustc -T help`. Target options must be +set to the same value across all crates in the dependency graph. diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index d683dedd2d369..6e1bac7645b89 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::DiagCtxtHandle; use rustc_session::config::{ self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns, - OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, nightly_options, + OutFileName, Sysroot, TargetOptions, UnstableOptions, get_cmd_lint_options, nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple, }; use rustc_session::lint::Level; @@ -88,6 +88,10 @@ pub(crate) struct Options { pub(crate) codegen_options: CodegenOptions, /// Codegen options strings to hand to the compiler. pub(crate) codegen_options_strs: Vec, + /// Target options to hand to the compiler. + pub(crate) target_opts: TargetOptions, + /// Target options strings to hand to the compiler. + pub(crate) target_opts_strs: Vec, /// Unstable (`-Z`) options to pass to the compiler. pub(crate) unstable_opts: UnstableOptions, /// Unstable (`-Z`) options strings to pass to the compiler. @@ -408,6 +412,13 @@ impl Options { let mut collected_options = Default::default(); let codegen_options = CodegenOptions::build(early_dcx, matches, &mut collected_options); let unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); + let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); + TargetOptions::require_unstable_options( + early_dcx, + &collected_options.metadata, + #[allow(rustc::bad_opt_access)] + unstable_opts.unstable_options, + ); let remap_path_prefix = match parse_remap_path_prefix(matches) { Ok(prefix_mappings) => prefix_mappings, @@ -873,6 +884,7 @@ impl Options { let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from); let test_builder = matches.opt_str("test-builder").map(PathBuf::from); let codegen_options_strs = matches.opt_strs("C"); + let target_opts_strs = matches.opt_strs("T"); let unstable_opts_strs = matches.opt_strs("Z"); let lib_strs = matches.opt_strs("L"); let extern_strs = matches.opt_strs("extern"); @@ -928,6 +940,8 @@ impl Options { check_cfgs, codegen_options, codegen_options_strs, + target_opts, + target_opts_strs, unstable_opts, unstable_opts_strs, target, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index cb6766fecaa5d..3561f44aa008d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -218,6 +218,7 @@ pub(crate) fn create_config( check_cfgs, codegen_options, unstable_opts, + target_opts, target, edition, sysroot, @@ -279,6 +280,7 @@ pub(crate) fn create_config( actually_rustdoc: true, resolve_doc_links, unstable_opts, + target_opts, error_format, diagnostic_width, edition, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 7b0bfabf49ba6..76a8d5c275d97 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -112,6 +112,9 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) -> for codegen_options_str in &options.codegen_options_strs { content.push(format!("-C{codegen_options_str}")); } + for target_option_str in &options.target_opts_strs { + content.push(format!("-T{target_option_str}")); + } for unstable_option_str in &options.unstable_opts_strs { content.push(format!("-Z{unstable_option_str}")); } @@ -172,6 +175,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions crate_name: options.crate_name.clone(), remap_path_prefix: options.remap_path_prefix.clone(), remap_path_scope: options.remap_path_scope.clone(), + target_opts: options.target_opts.clone(), unstable_opts: options.unstable_opts.clone(), error_format: options.error_format.clone(), ..config::Options::default() diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 215552e8909be..8c9bbffb70eda 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -236,6 +236,14 @@ fn opts() -> Vec { "", ), opt(Stable, Multi, "C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]"), + opt( + Stable, + Multi, + "T", + "target-modifier", + "pass a target modifier option to rustc", + "[=]", + ), opt(Stable, FlagMulti, "", "document-private-items", "document private items", ""), opt( Unstable, diff --git a/tests/run-make/rustc-help/help-v.diff b/tests/run-make/rustc-help/help-v.diff index 94ed6a0ed027c..d64226d39b7ae 100644 --- a/tests/run-make/rustc-help/help-v.diff +++ b/tests/run-make/rustc-help/help-v.diff @@ -1,5 +1,5 @@ -@@ -65,10 +65,31 @@ - Set a codegen option +@@ -67,11 +67,32 @@ + Set a target modifier option -V, --version Print version info and exit -v, --verbose Use verbose output + --extern [=] @@ -27,6 +27,7 @@ Additional help: -C help Print codegen options + -T help Print target modifier options -W help Print 'lint' options and default settings -Z help Print unstable compiler options - --help -v Print the full set of options rustc accepts diff --git a/tests/run-make/rustc-help/help-v.stdout b/tests/run-make/rustc-help/help-v.stdout index 1531f61089e9a..01567e6b97883 100644 --- a/tests/run-make/rustc-help/help-v.stdout +++ b/tests/run-make/rustc-help/help-v.stdout @@ -63,6 +63,8 @@ Options: lints are capped at this level -C, --codegen [=] Set a codegen option + -T, --target-modifier [=] + Set a target modifier option -V, --version Print version info and exit -v, --verbose Use verbose output --extern [=] @@ -90,6 +92,7 @@ Options: Additional help: -C help Print codegen options + -T help Print target modifier options -W help Print 'lint' options and default settings -Z help Print unstable compiler options diff --git a/tests/run-make/rustc-help/help.stdout b/tests/run-make/rustc-help/help.stdout index f96feccf35980..4505824f75a82 100644 --- a/tests/run-make/rustc-help/help.stdout +++ b/tests/run-make/rustc-help/help.stdout @@ -63,11 +63,14 @@ Options: lints are capped at this level -C, --codegen [=] Set a codegen option + -T, --target-modifier [=] + Set a target modifier option -V, --version Print version info and exit -v, --verbose Use verbose output Additional help: -C help Print codegen options + -T help Print target modifier options -W help Print 'lint' options and default settings -Z help Print unstable compiler options --help -v Print the full set of options rustc accepts diff --git a/tests/run-make/rustdoc/default-output/output-default.stdout b/tests/run-make/rustdoc/default-output/output-default.stdout index 78dfbf03c1b10..1c9e712b49136 100644 --- a/tests/run-make/rustdoc/default-output/output-default.stdout +++ b/tests/run-make/rustdoc/default-output/output-default.stdout @@ -29,6 +29,8 @@ Options: `html_root_url` -C, --codegen OPT[=VALUE] pass a codegen option to rustc + -T, --target-modifier [=] + pass a target modifier option to rustc --document-private-items document private items --document-hidden-items From ad7081d117d1ce7e21011bf02eb3d842190d14b0 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 21 Jul 2026 10:05:27 +0000 Subject: [PATCH 05/29] sess: mark target modifier options are unstable Introduce a generic mechanism for requiring `-Zunstable-options` on flags so this doesn't need to be checked per-flag manually. --- compiler/rustc_session/src/config.rs | 7 ++++- compiler/rustc_session/src/options.rs | 38 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 936ad0238dcf7..a39e1193205f3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2704,8 +2704,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let mut collected_options = Default::default(); - let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); + let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); + TargetOptions::require_unstable_options( + early_dcx, + &collected_options.metadata, + unstable_opts.unstable_options, + ); // `-Zassumptions-on-binders` requires the next trait solver globally. Normalize after // parsing so the effective config is independent of flag order and so consumers that diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 4da8a0074f44e..3dbe22caf95d4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -41,6 +41,7 @@ macro_rules! insert { macro_rules! hash_opt { ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}}; ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }}; + ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED_UNSTABLE]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }}; ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{ if !$for_crate_hash { insert!($opt_name, $opt_expr, $sub_hashes) @@ -52,6 +53,7 @@ macro_rules! hash_opt { macro_rules! hash_substruct { ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}}; ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}}; + ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_UNSTABLE]) => {{}}; ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}}; ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {{ use crate::config::dep_tracking::DepTrackingHash; @@ -438,6 +440,25 @@ macro_rules! options { } } +macro_rules! require_unstable_options { + ($opt_name:ident, $group_name:ident, [UNTRACKED], + ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; + ($opt_name:ident, $group_name:ident, [TRACKED], + ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; + ($opt_name:ident, $group_name:ident, [TRACKED_UNSTABLE], + ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{ + if $meta.$group_name.$opt_name.is_set && !$unstable_opts { + $early_dcx + .early_err(format!("`-T{}` requires `-Zunstable-options`", stringify!($opt_name))) + .raise_fatal(); + } + }}; + ($opt_name:ident, $group_name:ident, [TRACKED_NO_CRATE_HASH], + ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; + ($opt_name:ident, $group_name:ident, [SUBSTRUCT], + ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; +} + trait TargetModifierOptionValue { fn to_string_for_diag(&self) -> String; } @@ -518,6 +539,21 @@ macro_rules! target_modifier_options { out.join("\n") } + pub fn require_unstable_options( + early_dcx: &EarlyDiagCtxt, + meta: &OptionsMetadata, + unstable_opts: bool + ) { + $( + require_unstable_options!( + $opt, + $group_name, + [$dep_tracking_marker], + (early_dcx, meta, unstable_opts) + ); + )* + } + pub fn is_target_modifier(name: &str) -> bool { let name = name.replace('-', "_"); match name.as_str() { @@ -2235,7 +2271,7 @@ target_modifier_options! { TargetOptions, TargetOptionsMetadata, T_OPTIONS, topts, "T", target, // tidy-alphabetical-start - fixed_x18: bool = (false, parse_bool, [TRACKED], + fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE], "make the x18 register reserved on AArch64 (default: no)"), // tidy-alphabetical-end From 71c3ea56d6c73efe38efb8037557e7a27acef683 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 06/29] sess: `-Tbranch-protection` --- compiler/rustc_interface/src/tests.rs | 16 ++++----- compiler/rustc_session/src/config.rs | 34 ++++++++++++++++--- compiler/rustc_session/src/diagnostics.rs | 2 +- compiler/rustc_session/src/options.rs | 12 +++++-- compiler/rustc_session/src/session.rs | 4 +-- tests/assembly-llvm/aarch64-pointer-auth.rs | 10 +++--- .../aarch64-naked-fn-no-bti-prolog.rs | 3 +- tests/codegen-llvm/branch-protection.rs | 20 +++++------ .../pointer-auth-link-with-c/rmake.rs | 6 ++-- ...protection-missing-pac-ret.BADFLAGS.stderr | 2 +- ...otection-missing-pac-ret.BADFLAGSPC.stderr | 2 +- ...rotection-missing-pac-ret.BADTARGET.stderr | 2 +- .../branch-protection-missing-pac-ret.rs | 13 +++---- 13 files changed, 81 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 3a681a0a30b4e..250f9ad48553e 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -709,6 +709,14 @@ fn test_target_options_tracking_hash() { // Make sure that changing a [TRACKED] option changes the hash. // tidy-alphabetical-start + tracked!( + branch_protection, + Some(BranchProtection { + bti: true, + pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }), + gcs: true, + }) + ); tracked!(fixed_x18, true); // tidy-alphabetical-end } @@ -809,14 +817,6 @@ fn test_unstable_options_tracking_hash() { tracked!(autodiff_post_passes, Some("function(mem2reg,instsimplify,simplifycfg)".to_string())); tracked!(binary_dep_depinfo, true); tracked!(box_noalias, false); - tracked!( - branch_protection, - Some(BranchProtection { - bti: true, - pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }), - gcs: true, - }) - ); tracked!(codegen_backend, Some("abc".to_string())); tracked!(codegen_emit_retag, Some(CodegenRetagOptions::default())); tracked!( diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index a39e1193205f3..6eb015425cd67 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -11,7 +11,7 @@ use std::num::NonZero; use std::path::{Path, PathBuf}; use std::str::{self, FromStr}; use std::sync::LazyLock; -use std::{cmp, fs, iter, thread}; +use std::{cmp, fmt, fs, iter, thread}; use externs::{ExternOpt, split_extern_opt}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; @@ -1597,26 +1597,51 @@ impl Passes { } } -#[derive(Clone, Copy, Hash, Debug, PartialEq)] +#[derive(Clone, Copy, Hash, Debug, PartialEq, Encodable, BlobDecodable)] pub enum PAuthKey { A, B, } -#[derive(Clone, Copy, Hash, Debug, PartialEq)] +#[derive(Clone, Copy, Hash, Debug, PartialEq, Encodable, BlobDecodable)] pub struct PacRet { pub leaf: bool, pub pc: bool, pub key: PAuthKey, } -#[derive(Clone, Copy, Hash, Debug, PartialEq, Default)] +#[derive(Clone, Copy, Hash, Debug, PartialEq, Default, Encodable, BlobDecodable)] pub struct BranchProtection { pub bti: bool, pub pac_ret: Option, pub gcs: bool, } +impl fmt::Display for BranchProtection { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut parts = Vec::new(); + if self.bti { + parts.push("bti"); + } + if let Some(pac_ret) = self.pac_ret { + parts.push("pac-ret"); + if pac_ret.leaf { + parts.push("leaf"); + } + if pac_ret.pc { + parts.push("pc"); + } + if matches!(pac_ret.key, PAuthKey::B) { + parts.push("b-key"); + } + } + if self.gcs { + parts.push("gcs"); + } + write!(f, "{}", parts.join(",")) + } +} + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] pub enum PointerAuthOption { // See and Clang's command line reference: @@ -1638,6 +1663,7 @@ pub enum PointerAuthOption { VTPtrTypeDisc, // tidy-alphabetical-end } + impl PointerAuthOption { pub fn parse(s: &str) -> Option { match s { diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 2d94185e44f16..8addc154e43c1 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -404,7 +404,7 @@ pub(crate) struct SmallDataThresholdNotSupportedForTarget<'a> { } #[derive(Diagnostic)] -#[diag("`-Zbranch-protection` is only supported on aarch64")] +#[diag("`-Tbranch-protection` is only supported on aarch64")] pub(crate) struct BranchProtectionRequiresAArch64; #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3dbe22caf95d4..2b3cc94928a6e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -475,6 +475,12 @@ impl TargetModifierOptionValue for u32 { } } +impl TargetModifierOptionValue for BranchProtection { + fn to_string_for_diag(&self) -> String { + self.to_string() + } +} + impl TargetModifierOptionValue for Option { fn to_string_for_diag(&self) -> String { match self { @@ -2271,6 +2277,9 @@ target_modifier_options! { TargetOptions, TargetOptionsMetadata, T_OPTIONS, topts, "T", target, // tidy-alphabetical-start + #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] + branch_protection: Option = (None, parse_branch_protection, [TRACKED_UNSTABLE], + "set options for branch target identification and pointer authentication on AArch64"), fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE], "make the x18 register reserved on AArch64 (default: no)"), // tidy-alphabetical-end @@ -2332,9 +2341,6 @@ options! { (default: no)"), box_noalias: bool = (true, parse_bool, [TRACKED], "emit noalias metadata for box (default: yes)"), - #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] - branch_protection: Option = (None, parse_branch_protection, [TRACKED], - "set options for branch target identification and pointer authentication on AArch64"), build_sdylib_interface: bool = (false, parse_bool, [UNTRACKED], "whether the stable interface is being built"), cache_proc_macros: bool = (false, parse_bool, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index f30d825b470ac..4b73c36c50dd8 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -962,7 +962,7 @@ impl Session { /// Accessing the session's unstable `branch_protection` option fields directly is linted /// against. pub fn branch_protection(&self) -> Option { - let mut bp = self.opts.unstable_opts.branch_protection; + let mut bp = self.opts.target_opts.branch_protection; if let Some(bp) = bp.as_mut() { // Windows on Arm only supports PAC Key B for return address signing, as shown in @@ -1554,7 +1554,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if sess.opts.unstable_opts.branch_protection.is_some() && sess.target.arch != Arch::AArch64 { + if sess.opts.target_opts.branch_protection.is_some() && sess.target.arch != Arch::AArch64 { sess.dcx().emit_err(diagnostics::BranchProtectionRequiresAArch64); } diff --git a/tests/assembly-llvm/aarch64-pointer-auth.rs b/tests/assembly-llvm/aarch64-pointer-auth.rs index 2406e8ccb5dc9..bc76e24d68fa1 100644 --- a/tests/assembly-llvm/aarch64-pointer-auth.rs +++ b/tests/assembly-llvm/aarch64-pointer-auth.rs @@ -4,12 +4,12 @@ //@ revisions: GCS PACRET PAUTHLR_NOP PAUTHLR //@ assembly-output: emit-asm //@ needs-llvm-components: aarch64 -//@ compile-flags: --target aarch64-unknown-linux-gnu +//@ compile-flags: --target aarch64-unknown-linux-gnu -Zunstable-options //@ [GCS] ignore-apple (XCode version needs updating) -//@ [GCS] compile-flags: -Z branch-protection=gcs -//@ [PACRET] compile-flags: -Z branch-protection=pac-ret,leaf -//@ [PAUTHLR_NOP] compile-flags: -Z branch-protection=pac-ret,pc,leaf -//@ [PAUTHLR] compile-flags: -C target-feature=+pauth-lr -Z branch-protection=pac-ret,pc,leaf +//@ [GCS] compile-flags: -T branch-protection=gcs +//@ [PACRET] compile-flags: -T branch-protection=pac-ret,leaf +//@ [PAUTHLR_NOP] compile-flags: -T branch-protection=pac-ret,pc,leaf +//@ [PAUTHLR] compile-flags: -C target-feature=+pauth-lr -T branch-protection=pac-ret,pc,leaf #![feature(no_core, lang_items)] #![no_std] diff --git a/tests/assembly-llvm/naked-functions/aarch64-naked-fn-no-bti-prolog.rs b/tests/assembly-llvm/naked-functions/aarch64-naked-fn-no-bti-prolog.rs index 430d4a59da6df..4ff020336ea73 100644 --- a/tests/assembly-llvm/naked-functions/aarch64-naked-fn-no-bti-prolog.rs +++ b/tests/assembly-llvm/naked-functions/aarch64-naked-fn-no-bti-prolog.rs @@ -1,4 +1,5 @@ -//@ compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti -Cunsafe-allow-abi-mismatch=branch-protection +//@ compile-flags: -C no-prepopulate-passes -Tbranch-protection=bti +//@ compile-flags: -Cunsafe-allow-abi-mismatch=branch-protection -Zunstable-options //@ assembly-output: emit-asm //@ needs-asm-support //@ only-aarch64 diff --git a/tests/codegen-llvm/branch-protection.rs b/tests/codegen-llvm/branch-protection.rs index 11847c256d6ba..75822e89cdf38 100644 --- a/tests/codegen-llvm/branch-protection.rs +++ b/tests/codegen-llvm/branch-protection.rs @@ -3,16 +3,16 @@ //@ add-minicore //@ revisions: BTI GCS PACRET LEAF BKEY PAUTHLR PAUTHLR_BKEY PAUTHLR_LEAF PAUTHLR_BTI NONE //@ needs-llvm-components: aarch64 -//@ [BTI] compile-flags: -Z branch-protection=bti -//@ [GCS] compile-flags: -Z branch-protection=gcs -//@ [PACRET] compile-flags: -Z branch-protection=pac-ret -//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf -//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key -//@ [PAUTHLR] compile-flags: -Z branch-protection=pac-ret,pc -//@ [PAUTHLR_BKEY] compile-flags: -Z branch-protection=pac-ret,pc,b-key -//@ [PAUTHLR_LEAF] compile-flags: -Z branch-protection=pac-ret,pc,leaf -//@ [PAUTHLR_BTI] compile-flags: -Z branch-protection=bti,pac-ret,pc -//@ compile-flags: --target aarch64-unknown-linux-gnu +//@ [BTI] compile-flags: -T branch-protection=bti +//@ [GCS] compile-flags: -T branch-protection=gcs +//@ [PACRET] compile-flags: -T branch-protection=pac-ret +//@ [LEAF] compile-flags: -T branch-protection=pac-ret,leaf +//@ [BKEY] compile-flags: -T branch-protection=pac-ret,b-key +//@ [PAUTHLR] compile-flags: -T branch-protection=pac-ret,pc +//@ [PAUTHLR_BKEY] compile-flags: -T branch-protection=pac-ret,pc,b-key +//@ [PAUTHLR_LEAF] compile-flags: -T branch-protection=pac-ret,pc,leaf +//@ [PAUTHLR_BTI] compile-flags: -T branch-protection=bti,pac-ret,pc +//@ compile-flags: --target aarch64-unknown-linux-gnu -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/run-make/pointer-auth-link-with-c/rmake.rs b/tests/run-make/pointer-auth-link-with-c/rmake.rs index 1ac68c95559c6..a863b2b8d1dfc 100644 --- a/tests/run-make/pointer-auth-link-with-c/rmake.rs +++ b/tests/run-make/pointer-auth-link-with-c/rmake.rs @@ -17,7 +17,8 @@ fn main() { build_native_static_lib("test"); rustc() .arg("-Cunsafe-allow-abi-mismatch=branch-protection") - .arg("-Zbranch-protection=bti,gcs,pac-ret,leaf") + .arg("-Zunstable-options") + .arg("-Tbranch-protection=bti,gcs,pac-ret,leaf") .input("test.rs") .run(); run("test"); @@ -31,7 +32,8 @@ fn main() { llvm_ar().obj_to_ar().output_input("libtest.a", &obj_file).run(); rustc() .arg("-Cunsafe-allow-abi-mismatch=branch-protection") - .arg("-Zbranch-protection=bti,gcs,pac-ret,leaf") + .arg("-Zunstable-options") + .arg("-Tbranch-protection=bti,gcs,pac-ret,leaf") .input("test.rs") .run(); run("test"); diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr index 277111a41f29c..fec7ced984393 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr @@ -1,2 +1,2 @@ -error: incorrect value `leaf` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected +error: incorrect value `leaf` for target option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr index e1ade01d2fe76..0a9157835aa91 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr @@ -1,2 +1,2 @@ -error: incorrect value `pc` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected +error: incorrect value `pc` for target option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADTARGET.stderr b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADTARGET.stderr index 7bc17c5c68c2b..0b55961eed727 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADTARGET.stderr +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADTARGET.stderr @@ -1,4 +1,4 @@ -error: `-Zbranch-protection` is only supported on aarch64 +error: `-Tbranch-protection` is only supported on aarch64 error: aborting due to 1 previous error diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs index bb23f9fe5c673..791c66b9efcf0 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs @@ -1,11 +1,12 @@ +//@ compile-flags: -Zunstable-options //@ revisions: BADFLAGS BADFLAGSPC BADTARGET -//@ [BADFLAGS] compile-flags: --target=aarch64-unknown-linux-gnu -Zbranch-protection=leaf +//@ [BADFLAGS] compile-flags: --target=aarch64-unknown-linux-gnu -Tbranch-protection=leaf //@ [BADFLAGS] check-fail //@ [BADFLAGS] needs-llvm-components: aarch64 -//@ [BADFLAGSPC] compile-flags: --target=aarch64-unknown-linux-gnu -Zbranch-protection=pc +//@ [BADFLAGSPC] compile-flags: --target=aarch64-unknown-linux-gnu -Tbranch-protection=pc //@ [BADFLAGSPC] check-fail //@ [BADFLAGSPC] needs-llvm-components: aarch64 -//@ [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti +//@ [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Tbranch-protection=bti //@ [BADTARGET] check-fail //@ [BADTARGET] needs-llvm-components: x86 @@ -22,6 +23,6 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -//[BADFLAGS]~? ERROR incorrect value `leaf` for unstable option `branch-protection` -//[BADFLAGSPC]~? ERROR incorrect value `pc` for unstable option `branch-protection` -//[BADTARGET]~? ERROR `-Zbranch-protection` is only supported on aarch64 +//[BADFLAGS]~? ERROR incorrect value `leaf` for target option `branch-protection` +//[BADFLAGSPC]~? ERROR incorrect value `pc` for target option `branch-protection` +//[BADTARGET]~? ERROR `-Tbranch-protection` is only supported on aarch64 From 4ba193332c0590c2ebc27a18ba542d997f27404f Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 07/29] sess: `-Tregparm` --- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_session/src/diagnostics.rs | 4 ++-- compiler/rustc_session/src/options.rs | 9 ++++----- compiler/rustc_session/src/session.rs | 2 +- tests/assembly-llvm/regparm-module-flag.rs | 8 ++++---- tests/codegen-llvm/regparm-inreg.rs | 11 ++++++----- .../regparm/regparm-valid-values.regparm4.stderr | 2 +- .../invalid/regparm/regparm-valid-values.rs | 14 +++++++------- .../invalid/regparm/requires-x86.aarch64.stderr | 2 +- .../compile-flags/invalid/regparm/requires-x86.rs | 6 +++--- .../invalid/regparm/requires-x86.x86_64.stderr | 2 +- .../ui/target_modifiers/auxiliary/wrong_regparm.rs | 2 +- .../incompatible_regparm.error_generated.stderr | 8 ++++---- tests/ui/target_modifiers/incompatible_regparm.rs | 4 ++-- 17 files changed, 41 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 8045e8ae9d28f..fd13da16fcc42 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -532,8 +532,8 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> { impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - regparm: self.tcx.sess.opts.unstable_opts.regparm, reg_struct_return: self.tcx.sess.opts.unstable_opts.reg_struct_return, + regparm: self.tcx.sess.opts.target_opts.regparm, } } } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 668072ff082ec..4ff48da2e2e0d 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -396,7 +396,7 @@ pub(crate) unsafe fn create_module<'ll>( } } - if let Some(regparm_count) = sess.opts.unstable_opts.regparm { + if let Some(regparm_count) = sess.opts.target_opts.regparm { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Error, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 250f9ad48553e..6b5a45595f579 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -718,6 +718,7 @@ fn test_target_options_tracking_hash() { }) ); tracked!(fixed_x18, true); + tracked!(regparm, Some(3)); // tidy-alphabetical-end } @@ -894,7 +895,6 @@ fn test_unstable_options_tracking_hash() { tracked!(profile_sample_use, Some(PathBuf::from("abc"))); tracked!(profiler_runtime, "abc".to_string()); tracked!(reg_struct_return, true); - tracked!(regparm, Some(3)); tracked!(relax_elf_relocations, Some(true)); tracked!(remap_cwd_prefix, Some(PathBuf::from("abc"))); tracked!(sanitizer, SanitizerSet::ADDRESS); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 562a40f182312..8edb5bd7c3c08 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -624,8 +624,8 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> { impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - regparm: self.sess.opts.unstable_opts.regparm, reg_struct_return: self.sess.opts.unstable_opts.reg_struct_return, + regparm: self.sess.opts.target_opts.regparm, } } } diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 8addc154e43c1..a3e4175ab655c 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -671,13 +671,13 @@ pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel; pub(crate) struct IndirectBranchCsPrefixRequiresX86OrX8664; #[derive(Diagnostic)] -#[diag("`-Zregparm={$regparm}` is unsupported (valid values 0-3)")] +#[diag("`-Tregparm={$regparm}` is unsupported (valid values 0-3)")] pub(crate) struct UnsupportedRegparm { pub(crate) regparm: u32, } #[derive(Diagnostic)] -#[diag("`-Zregparm=N` is only supported on x86")] +#[diag("`-Tregparm=N` is only supported on x86")] pub(crate) struct UnsupportedRegparmArch; #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2b3cc94928a6e..79aa962e5fcf6 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2282,6 +2282,10 @@ target_modifier_options! { "set options for branch target identification and pointer authentication on AArch64"), fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE], "make the x18 register reserved on AArch64 (default: no)"), + regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE], + "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ + in registers EAX, EDX, and ECX instead of on the stack for\ + \"C\", \"cdecl\", and \"stdcall\" fn."), // tidy-alphabetical-end // If you add a new option, please update: @@ -2724,11 +2728,6 @@ options! { reg_struct_return: bool = (false, parse_bool, [TRACKED], "On x86-32 targets, it overrides the default ABI to return small structs in registers. It is UNSOUND to link together crates that use different values for this flag!"), - regparm: Option = (None, parse_opt_number, [TRACKED], - "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ - in registers EAX, EDX, and ECX instead of on the stack for\ - \"C\", \"cdecl\", and \"stdcall\" fn.\ - It is UNSOUND to link together crates that use different values for this flag!"), relax_elf_relocations: Option = (None, parse_opt_bool, [TRACKED], "whether ELF relocations can be relaxed"), remap_cwd_prefix: Option = (None, parse_opt_pathbuf, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 4b73c36c50dd8..bb4d5c7ec523a 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1622,7 +1622,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if let Some(regparm) = sess.opts.unstable_opts.regparm { + if let Some(regparm) = sess.opts.target_opts.regparm { if regparm > 3 { sess.dcx().emit_err(diagnostics::UnsupportedRegparm { regparm }); } diff --git a/tests/assembly-llvm/regparm-module-flag.rs b/tests/assembly-llvm/regparm-module-flag.rs index 4a08bfdf85e5f..72c96e968f5d1 100644 --- a/tests/assembly-llvm/regparm-module-flag.rs +++ b/tests/assembly-llvm/regparm-module-flag.rs @@ -2,11 +2,11 @@ // Issue: https://github.com/rust-lang/rust/issues/145271 //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static +//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static -Zunstable-options //@ revisions: REGPARM1 REGPARM2 REGPARM3 -//@[REGPARM1] compile-flags: -Zregparm=1 -//@[REGPARM2] compile-flags: -Zregparm=2 -//@[REGPARM3] compile-flags: -Zregparm=3 +//@[REGPARM1] compile-flags: -Tregparm=1 +//@[REGPARM2] compile-flags: -Tregparm=2 +//@[REGPARM3] compile-flags: -Tregparm=3 //@ needs-llvm-components: x86 #![feature(no_core)] #![no_std] diff --git a/tests/codegen-llvm/regparm-inreg.rs b/tests/codegen-llvm/regparm-inreg.rs index 77d4c206071e7..50ef809182f3e 100644 --- a/tests/codegen-llvm/regparm-inreg.rs +++ b/tests/codegen-llvm/regparm-inreg.rs @@ -3,14 +3,15 @@ // x86 only. //@ add-minicore -//@ compile-flags: --target i686-unknown-linux-gnu -Cno-prepopulate-passes -Copt-level=3 -Ctarget-feature=+avx +//@ compile-flags: --target i686-unknown-linux-gnu -Cno-prepopulate-passes -Copt-level=3 +//@ compile-flags: -Ctarget-feature=+avx -Zunstable-options //@ needs-llvm-components: x86 //@ revisions:regparm0 regparm1 regparm2 regparm3 -//@[regparm0] compile-flags: -Zregparm=0 -//@[regparm1] compile-flags: -Zregparm=1 -//@[regparm2] compile-flags: -Zregparm=2 -//@[regparm3] compile-flags: -Zregparm=3 +//@[regparm0] compile-flags: -Tregparm=0 +//@[regparm1] compile-flags: -Tregparm=1 +//@[regparm2] compile-flags: -Tregparm=2 +//@[regparm3] compile-flags: -Tregparm=3 #![crate_type = "lib"] #![no_core] diff --git a/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.regparm4.stderr b/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.regparm4.stderr index 8fc04adf57f56..81a5e846d5cc9 100644 --- a/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.regparm4.stderr +++ b/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.regparm4.stderr @@ -1,4 +1,4 @@ -error: `-Zregparm=4` is unsupported (valid values 0-3) +error: `-Tregparm=4` is unsupported (valid values 0-3) error: aborting due to 1 previous error diff --git a/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.rs b/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.rs index 6999eaac962aa..72364adb2a35f 100644 --- a/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.rs +++ b/tests/ui/compile-flags/invalid/regparm/regparm-valid-values.rs @@ -1,26 +1,26 @@ //@ revisions: regparm0 regparm1 regparm2 regparm3 regparm4 //@ needs-llvm-components: x86 -//@ compile-flags: --target i686-unknown-linux-gnu +//@ compile-flags: --target i686-unknown-linux-gnu -Zunstable-options //@[regparm0] check-pass -//@[regparm0] compile-flags: -Zregparm=0 +//@[regparm0] compile-flags: -Tregparm=0 //@[regparm1] check-pass -//@[regparm1] compile-flags: -Zregparm=1 +//@[regparm1] compile-flags: -Tregparm=1 //@[regparm2] check-pass -//@[regparm2] compile-flags: -Zregparm=2 +//@[regparm2] compile-flags: -Tregparm=2 //@[regparm3] check-pass -//@[regparm3] compile-flags: -Zregparm=3 +//@[regparm3] compile-flags: -Tregparm=3 //@[regparm4] check-fail -//@[regparm4] compile-flags: -Zregparm=4 +//@[regparm4] compile-flags: -Tregparm=4 //@ ignore-backends: gcc #![feature(no_core)] #![no_core] #![no_main] -//[regparm4]~? ERROR `-Zregparm=4` is unsupported (valid values 0-3) +//[regparm4]~? ERROR `-Tregparm=4` is unsupported (valid values 0-3) diff --git a/tests/ui/compile-flags/invalid/regparm/requires-x86.aarch64.stderr b/tests/ui/compile-flags/invalid/regparm/requires-x86.aarch64.stderr index 2433519f803c8..234edaa8860e4 100644 --- a/tests/ui/compile-flags/invalid/regparm/requires-x86.aarch64.stderr +++ b/tests/ui/compile-flags/invalid/regparm/requires-x86.aarch64.stderr @@ -1,4 +1,4 @@ -error: `-Zregparm=N` is only supported on x86 +error: `-Tregparm=N` is only supported on x86 error: aborting due to 1 previous error diff --git a/tests/ui/compile-flags/invalid/regparm/requires-x86.rs b/tests/ui/compile-flags/invalid/regparm/requires-x86.rs index 983e412376dc0..3c0f0432a4421 100644 --- a/tests/ui/compile-flags/invalid/regparm/requires-x86.rs +++ b/tests/ui/compile-flags/invalid/regparm/requires-x86.rs @@ -1,6 +1,6 @@ //@ revisions: x86 x86_64 aarch64 -//@ compile-flags: -Zregparm=3 +//@ compile-flags: -Tregparm=3 -Zunstable-options //@[x86] check-pass //@[x86] needs-llvm-components: x86 @@ -19,5 +19,5 @@ #![no_core] #![no_main] -//[x86_64]~? ERROR `-Zregparm=N` is only supported on x86 -//[aarch64]~? ERROR `-Zregparm=N` is only supported on x86 +//[x86_64]~? ERROR `-Tregparm=N` is only supported on x86 +//[aarch64]~? ERROR `-Tregparm=N` is only supported on x86 diff --git a/tests/ui/compile-flags/invalid/regparm/requires-x86.x86_64.stderr b/tests/ui/compile-flags/invalid/regparm/requires-x86.x86_64.stderr index 2433519f803c8..234edaa8860e4 100644 --- a/tests/ui/compile-flags/invalid/regparm/requires-x86.x86_64.stderr +++ b/tests/ui/compile-flags/invalid/regparm/requires-x86.x86_64.stderr @@ -1,4 +1,4 @@ -error: `-Zregparm=N` is only supported on x86 +error: `-Tregparm=N` is only supported on x86 error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/auxiliary/wrong_regparm.rs b/tests/ui/target_modifiers/auxiliary/wrong_regparm.rs index 267292faecd5a..b4de16f2806c1 100644 --- a/tests/ui/target_modifiers/auxiliary/wrong_regparm.rs +++ b/tests/ui/target_modifiers/auxiliary/wrong_regparm.rs @@ -1,5 +1,5 @@ //@ no-prefer-dynamic -//@ compile-flags: --target i686-unknown-linux-gnu -Zregparm=2 +//@ compile-flags: --target i686-unknown-linux-gnu -Tregparm=2 -Zunstable-options //@ needs-llvm-components: x86 #![feature(no_core)] diff --git a/tests/ui/target_modifiers/incompatible_regparm.error_generated.stderr b/tests/ui/target_modifiers/incompatible_regparm.error_generated.stderr index f58debe566789..cecd42bd6910c 100644 --- a/tests/ui/target_modifiers/incompatible_regparm.error_generated.stderr +++ b/tests/ui/target_modifiers/incompatible_regparm.error_generated.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm` +error: mixing `-Tregparm` will cause an ABI mismatch in crate `incompatible_regparm` --> $DIR/incompatible_regparm.rs:12:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm` - = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm` + = help: the `-Tregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: `-Tregparm=1` in this crate is incompatible with `-Tregparm=2` in dependency `wrong_regparm` + = help: set `-Tregparm=2` in this crate or `-Tregparm=1` in `wrong_regparm` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/incompatible_regparm.rs b/tests/ui/target_modifiers/incompatible_regparm.rs index c6261b4c6c986..c770f08b7e3b7 100644 --- a/tests/ui/target_modifiers/incompatible_regparm.rs +++ b/tests/ui/target_modifiers/incompatible_regparm.rs @@ -1,5 +1,5 @@ //@ aux-build:wrong_regparm.rs -//@ compile-flags: --target i686-unknown-linux-gnu -Zregparm=1 +//@ compile-flags: --target i686-unknown-linux-gnu -Tregparm=1 -Zunstable-options //@ needs-llvm-components: x86 //@ revisions:allow_regparm_mismatch allow_no_value error_generated @@ -10,7 +10,7 @@ //@ ignore-backends: gcc #![feature(no_core)] -//[error_generated]~^ ERROR mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm` +//[error_generated]~^ ERROR mixing `-Tregparm` will cause an ABI mismatch in crate `incompatible_regparm` #![crate_type = "rlib"] #![no_core] From cbbe1547ae4629304bde564cb8c87053e4a085e6 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 08/29] sess: `-Tindirect-branch-cs-prefix` --- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_session/src/diagnostics.rs | 2 +- compiler/rustc_session/src/options.rs | 4 ++-- compiler/rustc_session/src/session.rs | 2 +- tests/codegen-llvm/indirect-branch-cs-prefix.rs | 2 +- .../requires-x86-or-x86_64.aarch64.stderr | 2 +- .../indirect-branch-cs-prefix/requires-x86-or-x86_64.rs | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 4ff48da2e2e0d..91553dc742793 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -514,7 +514,7 @@ pub(crate) unsafe fn create_module<'ll>( ); } - if sess.opts.unstable_opts.indirect_branch_cs_prefix { + if sess.opts.target_opts.indirect_branch_cs_prefix { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Override, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 6b5a45595f579..e737b9d164092 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -718,6 +718,7 @@ fn test_target_options_tracking_hash() { }) ); tracked!(fixed_x18, true); + tracked!(indirect_branch_cs_prefix, true); tracked!(regparm, Some(3)); // tidy-alphabetical-end } @@ -851,7 +852,6 @@ fn test_unstable_options_tracking_hash() { tracked!(human_readable_cgu_names, true); tracked!(implicit_sysroot_deps, false); tracked!(incremental_ignore_spans, true); - tracked!(indirect_branch_cs_prefix, true); tracked!(inline_mir, Some(true)); tracked!(inline_mir_hint_threshold, Some(123)); tracked!(inline_mir_threshold, Some(123)); diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index a3e4175ab655c..16dfe3a217892 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -667,7 +667,7 @@ pub(crate) struct FunctionReturnRequiresX86OrX8664; pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel; #[derive(Diagnostic)] -#[diag("`-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64")] +#[diag("`-Tindirect-branch-cs-prefix` is only supported on x86 and x86_64")] pub(crate) struct IndirectBranchCsPrefixRequiresX86OrX8664; #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 79aa962e5fcf6..f2cadf544fda2 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2282,6 +2282,8 @@ target_modifier_options! { "set options for branch target identification and pointer authentication on AArch64"), fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE], "make the x18 register reserved on AArch64 (default: no)"), + indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE], + "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE], "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ in registers EAX, EDX, and ECX instead of on the stack for\ @@ -2501,8 +2503,6 @@ options! { - hashes of green query instances - hash collisions of query keys - hash collisions when creating dep-nodes"), - indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED], - "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), inline_llvm: bool = (true, parse_bool, [TRACKED], "enable LLVM inlining (default: yes)"), inline_mir: Option = (None, parse_opt_bool, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index bb4d5c7ec523a..6c14843cfd6f5 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1616,7 +1616,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if sess.opts.unstable_opts.indirect_branch_cs_prefix { + if sess.opts.target_opts.indirect_branch_cs_prefix { if !matches!(sess.target.arch, Arch::X86 | Arch::X86_64) { sess.dcx().emit_err(diagnostics::IndirectBranchCsPrefixRequiresX86OrX8664); } diff --git a/tests/codegen-llvm/indirect-branch-cs-prefix.rs b/tests/codegen-llvm/indirect-branch-cs-prefix.rs index 9ad7f9d9afa68..7f97d4d97dbfa 100644 --- a/tests/codegen-llvm/indirect-branch-cs-prefix.rs +++ b/tests/codegen-llvm/indirect-branch-cs-prefix.rs @@ -5,7 +5,7 @@ //@ revisions: unset set //@ needs-llvm-components: x86 //@ compile-flags: --target x86_64-unknown-linux-gnu -//@ [set] compile-flags: -Zindirect-branch-cs-prefix +//@ [set] compile-flags: -Tindirect-branch-cs-prefix -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.aarch64.stderr b/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.aarch64.stderr index e3f7871da3524..aa74adb1b7946 100644 --- a/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.aarch64.stderr +++ b/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.aarch64.stderr @@ -1,4 +1,4 @@ -error: `-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64 +error: `-Tindirect-branch-cs-prefix` is only supported on x86 and x86_64 error: aborting due to 1 previous error diff --git a/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.rs b/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.rs index f0409a6f07796..f9ad12e907920 100644 --- a/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.rs +++ b/tests/ui/compile-flags/invalid/indirect-branch-cs-prefix/requires-x86-or-x86_64.rs @@ -1,6 +1,6 @@ //@ revisions: x86 x86_64 aarch64 -//@ compile-flags: -Zindirect-branch-cs-prefix +//@ compile-flags: -Tindirect-branch-cs-prefix -Zunstable-options //@[x86] check-pass //@[x86] needs-llvm-components: x86 @@ -19,4 +19,4 @@ #![no_core] #![no_main] -//[aarch64]~? ERROR `-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64 +//[aarch64]~? ERROR `-Tindirect-branch-cs-prefix` is only supported on x86 and x86_64 From 2574136fab93d552e21403384cccc8ee75ae1854 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 09/29] sess: `-Tfixed-x18` --- compiler/rustc_codegen_llvm/src/diagnostics.rs | 2 +- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_interface/src/tests.rs | 1 - compiler/rustc_session/src/options.rs | 2 -- compiler/rustc_session/src/session.rs | 2 +- compiler/rustc_target/src/target_features.rs | 2 +- tests/codegen-llvm/asm/aarch64-clobbers.rs | 2 +- tests/codegen-llvm/fixed-x18.rs | 2 +- tests/run-make/rustdoc/target-modifiers/rmake.rs | 14 +++++++++----- tests/ui/abi/fixed_x18.rs | 6 +++--- tests/ui/target_modifiers/auxiliary/fixed_x18.rs | 2 +- .../incompatible_fixedx18.error_generated.stderr | 8 ++++---- tests/ui/target_modifiers/incompatible_fixedx18.rs | 4 ++-- 13 files changed, 25 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/diagnostics.rs b/compiler/rustc_codegen_llvm/src/diagnostics.rs index 54f8ffbb881da..99c7251d5715b 100644 --- a/compiler/rustc_codegen_llvm/src/diagnostics.rs +++ b/compiler/rustc_codegen_llvm/src/diagnostics.rs @@ -218,7 +218,7 @@ pub(crate) struct MismatchedDataLayout<'a> { } #[derive(Diagnostic)] -#[diag("the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture")] +#[diag("the `-Tfixed-x18` flag is not supported on the `{$arch}` architecture")] pub(crate) struct FixedX18InvalidArch<'a> { pub arch: &'a str, } diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index feccbd953cc1c..c95056fc41f3a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -638,7 +638,7 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec) { target_features::sanitizer_features_by_flags(sess, features); // -Zfixed-x18 - if sess.opts.unstable_opts.fixed_x18 { + if sess.opts.target_opts.fixed_x18 { if sess.target.arch != Arch::AArch64 { sess.dcx() .emit_fatal(diagnostics::FixedX18InvalidArch { arch: sess.target.arch.desc() }); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e737b9d164092..e96246a432390 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -842,7 +842,6 @@ fn test_unstable_options_tracking_hash() { tracked!(embed_source, true); tracked!(export_executable_symbols, true); tracked!(fewer_names, Some(true)); - tracked!(fixed_x18, true); tracked!(flatten_format_args, false); tracked!(fmt_debug, FmtDebug::Shallow); tracked!(force_unstable_if_unmarked, true); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index f2cadf544fda2..4ba9c3cf4e9e2 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2452,8 +2452,6 @@ options! { fewer_names: Option = (None, parse_opt_bool, [TRACKED], "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \ (default: no)"), - fixed_x18: bool = (false, parse_bool, [TRACKED], - "make the x18 register reserved on AArch64 (default: no)"), flatten_format_args: bool = (true, parse_bool, [TRACKED], "flatten nested format_args!() and literals into a simplified format_args!() call \ (default: yes)"), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 6c14843cfd6f5..17763dbb94b09 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1435,7 +1435,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { let mut unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers; // Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled // we should allow Shadow Call Stack sanitizer. - if sess.opts.unstable_opts.fixed_x18 && sess.target.arch == Arch::AArch64 { + if sess.opts.target_opts.fixed_x18 && sess.target.arch == Arch::AArch64 { unsupported_sanitizers -= SanitizerSet::SHADOWCALLSTACK; } match unsupported_sanitizers.into_iter().count() { diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index f1dd2d8191985..347bd527975c2 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -321,7 +321,7 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ( "reserve-x18", // Not implied by any CPU model or other feature; the compiler flag is a target modifier. - InternalOnly { reason: "use `-Zfixed-x18` compiler flag instead", hard_error: false }, + InternalOnly { reason: "use `-Tfixed-x18` compiler flag instead", hard_error: false }, &[], ), // FEAT_SB diff --git a/tests/codegen-llvm/asm/aarch64-clobbers.rs b/tests/codegen-llvm/asm/aarch64-clobbers.rs index e86956cb47977..d59fb0d0b793d 100644 --- a/tests/codegen-llvm/asm/aarch64-clobbers.rs +++ b/tests/codegen-llvm/asm/aarch64-clobbers.rs @@ -2,7 +2,7 @@ //@ revisions: aarch64 aarch64_fixed_x18 aarch64_no_x18 aarch64_reserve_x18 arm64ec //@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu //@[aarch64] needs-llvm-components: aarch64 -//@[aarch64_fixed_x18] compile-flags: --target aarch64-unknown-linux-gnu -Zfixed-x18 +//@[aarch64_fixed_x18] compile-flags: --target aarch64-unknown-linux-gnu -Tfixed-x18 -Zunstable-options //@[aarch64_fixed_x18] needs-llvm-components: aarch64 //@[aarch64_no_x18] compile-flags: --target aarch64-pc-windows-msvc //@[aarch64_no_x18] needs-llvm-components: aarch64 diff --git a/tests/codegen-llvm/fixed-x18.rs b/tests/codegen-llvm/fixed-x18.rs index 2020c2ea18305..696af8219971a 100644 --- a/tests/codegen-llvm/fixed-x18.rs +++ b/tests/codegen-llvm/fixed-x18.rs @@ -5,7 +5,7 @@ //@ revisions: unset set //@ needs-llvm-components: aarch64 //@ compile-flags: --target aarch64-unknown-none -//@ [set] compile-flags: -Zfixed-x18 +//@ [set] compile-flags: -Tfixed-x18 -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/run-make/rustdoc/target-modifiers/rmake.rs b/tests/run-make/rustdoc/target-modifiers/rmake.rs index ffe87f3f7650e..7264b9407f1a3 100644 --- a/tests/run-make/rustdoc/target-modifiers/rmake.rs +++ b/tests/run-make/rustdoc/target-modifiers/rmake.rs @@ -15,7 +15,8 @@ fn main() { .emit("metadata") .sysroot("/dev/null") .target("aarch64-unknown-none-softfloat") - .arg("-Zfixed-x18") + .arg("-Tfixed-x18") + .arg("-Zunstable-options") .run(); rustdoc() @@ -23,7 +24,8 @@ fn main() { .crate_type("rlib") .extern_("d", "libd.rmeta") .target("aarch64-unknown-none-softfloat") - .arg("-Zfixed-x18") + .arg("-Tfixed-x18") + .arg("-Zunstable-options") .run(); rustdoc() @@ -31,7 +33,8 @@ fn main() { .crate_type("rlib") .extern_("d", "libd.rmeta") .target("aarch64-unknown-none-softfloat") - .arg("-Zfixed-x18") + .arg("-Tfixed-x18") + .arg("-Zunstable-options") .arg("--test") .run(); @@ -41,7 +44,8 @@ fn main() { .crate_type("rlib") .extern_("d", "libd.rmeta") .target("aarch64-unknown-none-softfloat") - .arg("-Zfixed-x18") + .arg("-Tfixed-x18") + .arg("-Zunstable-options") .arg("--test") .run(); @@ -53,7 +57,7 @@ fn main() { .target("aarch64-unknown-none-softfloat") .arg("--test") .run_fail() - .assert_stderr_contains("mixing `-Zfixed-x18` will cause an ABI mismatch"); + .assert_stderr_contains("mixing `-Tfixed-x18` will cause an ABI mismatch"); // rustdoc --test -Cunsafe-allow-abi-mismatch=... ignores the mismatch rustdoc() diff --git a/tests/ui/abi/fixed_x18.rs b/tests/ui/abi/fixed_x18.rs index 0f09b0105fca5..cd1b84bb13ecf 100644 --- a/tests/ui/abi/fixed_x18.rs +++ b/tests/ui/abi/fixed_x18.rs @@ -1,10 +1,10 @@ -// This tests that -Zfixed-x18 causes a compilation failure on targets other than aarch64. +// This tests that -Tfixed-x18 causes a compilation failure on targets other than aarch64. // Behavior on aarch64 is tested by tests/codegen-llvm/fixed-x18.rs. // //@ revisions: x64 i686 arm riscv32 riscv64 //@ dont-check-compiler-stderr // -//@ compile-flags: -Zfixed-x18 +//@ compile-flags: -Tfixed-x18 -Zunstable-options //@ [x64] needs-llvm-components: x86 //@ [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib //@ [i686] needs-llvm-components: x86 @@ -28,4 +28,4 @@ trait MetaSized: PointeeSized {} #[lang = "sized"] trait Sized: MetaSized {} -//~? ERROR the `-Zfixed-x18` flag is not supported on the ` +//~? ERROR the `-Tfixed-x18` flag is not supported on the ` diff --git a/tests/ui/target_modifiers/auxiliary/fixed_x18.rs b/tests/ui/target_modifiers/auxiliary/fixed_x18.rs index 32eff76ec54c4..b42b03a22e3f9 100644 --- a/tests/ui/target_modifiers/auxiliary/fixed_x18.rs +++ b/tests/ui/target_modifiers/auxiliary/fixed_x18.rs @@ -1,5 +1,5 @@ //@ no-prefer-dynamic -//@ compile-flags: --target aarch64-unknown-none -Zfixed-x18 +//@ compile-flags: --target aarch64-unknown-none -Tfixed-x18 -Zunstable-options //@ needs-llvm-components: aarch64 #![feature(no_core)] diff --git a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr index bcdee625830a7..d5e6155b70e96 100644 --- a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr +++ b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18` +error: mixing `-Tfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18` --> $DIR/incompatible_fixedx18.rs:13:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zfixed-x18` is unset in this crate which is incompatible with `-Zfixed-x18` being set in dependency `fixed_x18` - = help: set `-Zfixed-x18` in this crate or unset `-Zfixed-x18` in `fixed_x18` + = help: the `-Tfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Tfixed-x18` in this crate is incompatible with `-Tfixed-x18=true` in dependency `fixed_x18` + = help: set `-Tfixed-x18=true` in this crate or unset `-Tfixed-x18` in `fixed_x18` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=fixed-x18` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/incompatible_fixedx18.rs b/tests/ui/target_modifiers/incompatible_fixedx18.rs index 320cf0137e510..abbcfc656d4f2 100644 --- a/tests/ui/target_modifiers/incompatible_fixedx18.rs +++ b/tests/ui/target_modifiers/incompatible_fixedx18.rs @@ -3,7 +3,7 @@ //@ needs-llvm-components: aarch64 //@ revisions:allow_match allow_mismatch error_generated -//@[allow_match] compile-flags: -Zfixed-x18 +//@[allow_match] compile-flags: -Tfixed-x18 -Zunstable-options //@[allow_mismatch] compile-flags: -Cunsafe-allow-abi-mismatch=fixed-x18 // [error_generated] no extra compile-flags //@[allow_mismatch] check-pass @@ -11,7 +11,7 @@ //@ ignore-backends: gcc #![feature(no_core)] -//[error_generated]~^ ERROR mixing `-Zfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18` +//[error_generated]~^ ERROR mixing `-Tfixed-x18` will cause an ABI mismatch in crate `incompatible_fixedx18` #![crate_type = "rlib"] #![no_core] From c751a8357f9249b6db49fb5eeb5e586fa57fdfe0 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 10/29] sess: `-Tretpoline{,-external-thunk}` --- compiler/rustc_codegen_ssa/src/target_features.rs | 10 +++++----- compiler/rustc_interface/src/tests.rs | 2 ++ compiler/rustc_session/src/config.rs | 6 +++--- compiler/rustc_session/src/options.rs | 5 +++++ tests/codegen-llvm/retpoline.rs | 4 ++-- .../ui/target-feature/retpoline-target-feature-flag.rs | 4 ++-- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 69487d2039c31..a2caca6df0dd1 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -489,17 +489,17 @@ pub fn flag_to_backend_features<'a>( /// Computes the backend target features to be added to account for retpoline flags. /// Used by both LLVM and GCC since their target features are, conveniently, the same. pub fn retpoline_features_by_flags(sess: &Session, features: &mut Vec) { - // -Zretpoline without -Zretpoline-external-thunk enables + // -Tretpoline without -Tretpoline-external-thunk enables // retpoline-indirect-branches and retpoline-indirect-calls target features - let unstable_opts = &sess.opts.unstable_opts; - if unstable_opts.retpoline && !unstable_opts.retpoline_external_thunk { + let target_opts = &sess.opts.target_opts; + if target_opts.retpoline && !target_opts.retpoline_external_thunk { features.push("+retpoline-indirect-branches".into()); features.push("+retpoline-indirect-calls".into()); } - // -Zretpoline-external-thunk (maybe, with -Zretpoline too) enables + // -Tretpoline-external-thunk (maybe, with -Tretpoline too) enables // retpoline-external-thunk, retpoline-indirect-branches and // retpoline-indirect-calls target features - if unstable_opts.retpoline_external_thunk { + if target_opts.retpoline_external_thunk { features.push("+retpoline-external-thunk".into()); features.push("+retpoline-indirect-branches".into()); features.push("+retpoline-indirect-calls".into()); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e96246a432390..61c82586a488a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -720,6 +720,8 @@ fn test_target_options_tracking_hash() { tracked!(fixed_x18, true); tracked!(indirect_branch_cs_prefix, true); tracked!(regparm, Some(3)); + tracked!(retpoline, true); + tracked!(retpoline_external_thunk, true); // tidy-alphabetical-end } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 6eb015425cd67..8a5bb54b75bfc 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2731,7 +2731,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let mut collected_options = Default::default(); let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); - let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); + let mut target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); TargetOptions::require_unstable_options( early_dcx, &collected_options.metadata, @@ -2924,8 +2924,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let prints = print_request::collect_print_requests(early_dcx, &mut cg, &unstable_opts, matches); // -Zretpoline-external-thunk also requires -Zretpoline - if unstable_opts.retpoline_external_thunk { - unstable_opts.retpoline = true; + if target_opts.retpoline_external_thunk { + target_opts.retpoline = true; } let cg = cg; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 4ba9c3cf4e9e2..70954949bcdaf 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2288,6 +2288,11 @@ target_modifier_options! { "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ in registers EAX, EDX, and ECX instead of on the stack for\ \"C\", \"cdecl\", and \"stdcall\" fn."), + retpoline: bool = (false, parse_bool, [TRACKED_UNSTABLE], + "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), + retpoline_external_thunk: bool = (false, parse_bool, [TRACKED_UNSTABLE], + "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ + target features (default: no)"), // tidy-alphabetical-end // If you add a new option, please update: diff --git a/tests/codegen-llvm/retpoline.rs b/tests/codegen-llvm/retpoline.rs index 89313d02db130..28ac9c5077ff9 100644 --- a/tests/codegen-llvm/retpoline.rs +++ b/tests/codegen-llvm/retpoline.rs @@ -7,8 +7,8 @@ //@ revisions: disabled enabled_retpoline enabled_retpoline_external_thunk //@ needs-llvm-components: x86 //@ compile-flags: --target x86_64-unknown-linux-gnu -//@ [enabled_retpoline] compile-flags: -Zretpoline -//@ [enabled_retpoline_external_thunk] compile-flags: -Zretpoline-external-thunk +//@ [enabled_retpoline] compile-flags: -Tretpoline -Zunstable-options +//@ [enabled_retpoline_external_thunk] compile-flags: -Tretpoline-external-thunk -Zunstable-options #![crate_type = "lib"] #![feature(no_core)] #![no_core] diff --git a/tests/ui/target-feature/retpoline-target-feature-flag.rs b/tests/ui/target-feature/retpoline-target-feature-flag.rs index 182b5b86520ce..6d9db7b054781 100644 --- a/tests/ui/target-feature/retpoline-target-feature-flag.rs +++ b/tests/ui/target-feature/retpoline-target-feature-flag.rs @@ -1,8 +1,8 @@ //@ add-minicore //@ revisions: by_flag by_feature1 by_feature2 by_feature3 -//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib +//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib -Zunstable-options //@ needs-llvm-components: x86 -//@ [by_flag]compile-flags: -Zretpoline +//@ [by_flag]compile-flags: -Tretpoline //@ [by_feature1]compile-flags: -Ctarget-feature=+retpoline-external-thunk //@ [by_feature2]compile-flags: -Ctarget-feature=+retpoline-indirect-branches From 970fee08c741badba23c70dfe650a721c0c3e7c3 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 11/29] sess: `-Treg-struct-return` --- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_session/src/diagnostics.rs | 2 +- compiler/rustc_session/src/options.rs | 5 ++--- compiler/rustc_session/src/session.rs | 2 +- tests/assembly-llvm/reg-struct-return.rs | 4 ++-- tests/codegen-llvm/reg-struct-return.rs | 2 +- .../reg-struct-return/requires-x86.aarch64.stderr | 2 +- .../invalid/reg-struct-return/requires-x86.rs | 6 +++--- .../reg-struct-return/requires-x86.x86_64.stderr | 2 +- .../auxiliary/enabled_reg_struct_return.rs | 2 +- .../auxiliary/wrong_regparm_and_ret.rs | 3 ++- .../ui/target_modifiers/defaults_check.error.stderr | 8 ++++---- tests/ui/target_modifiers/defaults_check.rs | 8 ++++---- tests/ui/target_modifiers/no_value_bool.error.stderr | 8 ++++---- .../no_value_bool.error_explicit.stderr | 8 ++++---- tests/ui/target_modifiers/no_value_bool.rs | 12 ++++++------ tests/ui/target_modifiers/two_flags.rs | 4 ++-- 19 files changed, 42 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index fd13da16fcc42..11dbe30ed8a10 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -532,8 +532,8 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> { impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - reg_struct_return: self.tcx.sess.opts.unstable_opts.reg_struct_return, regparm: self.tcx.sess.opts.target_opts.regparm, + reg_struct_return: self.tcx.sess.opts.target_opts.reg_struct_return, } } } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 61c82586a488a..4b2ed08002cef 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -719,6 +719,7 @@ fn test_target_options_tracking_hash() { ); tracked!(fixed_x18, true); tracked!(indirect_branch_cs_prefix, true); + tracked!(reg_struct_return, true); tracked!(regparm, Some(3)); tracked!(retpoline, true); tracked!(retpoline_external_thunk, true); @@ -895,7 +896,6 @@ fn test_unstable_options_tracking_hash() { tracked!(precise_enum_drop_elaboration, false); tracked!(profile_sample_use, Some(PathBuf::from("abc"))); tracked!(profiler_runtime, "abc".to_string()); - tracked!(reg_struct_return, true); tracked!(relax_elf_relocations, Some(true)); tracked!(remap_cwd_prefix, Some(PathBuf::from("abc"))); tracked!(sanitizer, SanitizerSet::ADDRESS); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 8edb5bd7c3c08..c164b6c764c7b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -624,8 +624,8 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> { impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - reg_struct_return: self.sess.opts.unstable_opts.reg_struct_return, regparm: self.sess.opts.target_opts.regparm, + reg_struct_return: self.sess.opts.target_opts.reg_struct_return, } } } diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 16dfe3a217892..cc1acef60e914 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -681,7 +681,7 @@ pub(crate) struct UnsupportedRegparm { pub(crate) struct UnsupportedRegparmArch; #[derive(Diagnostic)] -#[diag("`-Zreg-struct-return` is only supported on x86")] +#[diag("`-Treg-struct-return` is only supported on x86")] pub(crate) struct UnsupportedRegStructReturnArch; #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 70954949bcdaf..8eb8b5a40e2f4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2284,6 +2284,8 @@ target_modifier_options! { "make the x18 register reserved on AArch64 (default: no)"), indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE], "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), + reg_struct_return: bool = (false, parse_bool, [TRACKED_UNSTABLE], + "On x86-32 targets, it overrides the default ABI to return small structs in registers."), regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE], "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ in registers EAX, EDX, and ECX instead of on the stack for\ @@ -2728,9 +2730,6 @@ options! { "enable queries of the dependency graph for regression testing (default: no)"), randomize_layout: bool = (false, parse_bool, [TRACKED], "randomize the layout of types (default: no)"), - reg_struct_return: bool = (false, parse_bool, [TRACKED], - "On x86-32 targets, it overrides the default ABI to return small structs in registers. - It is UNSOUND to link together crates that use different values for this flag!"), relax_elf_relocations: Option = (None, parse_opt_bool, [TRACKED], "whether ELF relocations can be relaxed"), remap_cwd_prefix: Option = (None, parse_opt_pathbuf, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 17763dbb94b09..737d6ff17dc8c 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1630,7 +1630,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { sess.dcx().emit_err(diagnostics::UnsupportedRegparmArch); } } - if sess.opts.unstable_opts.reg_struct_return { + if sess.opts.target_opts.reg_struct_return { if sess.target.arch != Arch::X86 { sess.dcx().emit_err(diagnostics::UnsupportedRegStructReturnArch); } diff --git a/tests/assembly-llvm/reg-struct-return.rs b/tests/assembly-llvm/reg-struct-return.rs index d364954abe30d..9bb6ee973d1a5 100644 --- a/tests/assembly-llvm/reg-struct-return.rs +++ b/tests/assembly-llvm/reg-struct-return.rs @@ -7,9 +7,9 @@ //! `-Zreg-struct-return` is activated //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static +//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static -Zunstable-options //@ revisions: WITH WITHOUT -//@[WITH] compile-flags: -Zreg-struct-return +//@[WITH] compile-flags: -Treg-struct-return //@ needs-llvm-components: x86 #![feature(no_core)] diff --git a/tests/codegen-llvm/reg-struct-return.rs b/tests/codegen-llvm/reg-struct-return.rs index 52a1e174dfe6b..90f3d758b0cad 100644 --- a/tests/codegen-llvm/reg-struct-return.rs +++ b/tests/codegen-llvm/reg-struct-return.rs @@ -6,7 +6,7 @@ //@ revisions: ENABLED DISABLED //@ add-minicore //@ compile-flags: --target i686-unknown-linux-gnu -Cno-prepopulate-passes -Copt-level=3 -//@ [ENABLED] compile-flags: -Zreg-struct-return +//@ [ENABLED] compile-flags: -Treg-struct-return -Zunstable-options //@ needs-llvm-components: x86 #![crate_type = "lib"] diff --git a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.aarch64.stderr b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.aarch64.stderr index 9bc85cc7e62d8..99b7c4da1b889 100644 --- a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.aarch64.stderr +++ b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.aarch64.stderr @@ -1,4 +1,4 @@ -error: `-Zreg-struct-return` is only supported on x86 +error: `-Treg-struct-return` is only supported on x86 error: aborting due to 1 previous error diff --git a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.rs b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.rs index 321cf56cd2a0f..a09a73a87ff46 100644 --- a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.rs +++ b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.rs @@ -1,6 +1,6 @@ //@ revisions: x86 x86_64 aarch64 -//@ compile-flags: -Zreg-struct-return +//@ compile-flags: -Treg-struct-return -Zunstable-options //@[x86] check-pass //@[x86] needs-llvm-components: x86 @@ -19,5 +19,5 @@ #![no_core] #![no_main] -//[x86_64]~? ERROR `-Zreg-struct-return` is only supported on x86 -//[aarch64]~? ERROR `-Zreg-struct-return` is only supported on x86 +//[x86_64]~? ERROR `-Treg-struct-return` is only supported on x86 +//[aarch64]~? ERROR `-Treg-struct-return` is only supported on x86 diff --git a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.x86_64.stderr b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.x86_64.stderr index 9bc85cc7e62d8..99b7c4da1b889 100644 --- a/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.x86_64.stderr +++ b/tests/ui/compile-flags/invalid/reg-struct-return/requires-x86.x86_64.stderr @@ -1,4 +1,4 @@ -error: `-Zreg-struct-return` is only supported on x86 +error: `-Treg-struct-return` is only supported on x86 error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/auxiliary/enabled_reg_struct_return.rs b/tests/ui/target_modifiers/auxiliary/enabled_reg_struct_return.rs index 4bda4ba24c548..8f83a032e414d 100644 --- a/tests/ui/target_modifiers/auxiliary/enabled_reg_struct_return.rs +++ b/tests/ui/target_modifiers/auxiliary/enabled_reg_struct_return.rs @@ -1,5 +1,5 @@ //@ no-prefer-dynamic -//@ compile-flags: --target i686-unknown-linux-gnu -Zreg-struct-return=true +//@ compile-flags: --target i686-unknown-linux-gnu -Treg-struct-return=true -Zunstable-options //@ needs-llvm-components: x86 #![feature(no_core)] diff --git a/tests/ui/target_modifiers/auxiliary/wrong_regparm_and_ret.rs b/tests/ui/target_modifiers/auxiliary/wrong_regparm_and_ret.rs index 82ee3e71d16a8..a4bf165ab36ff 100644 --- a/tests/ui/target_modifiers/auxiliary/wrong_regparm_and_ret.rs +++ b/tests/ui/target_modifiers/auxiliary/wrong_regparm_and_ret.rs @@ -1,5 +1,6 @@ //@ no-prefer-dynamic -//@ compile-flags: --target i686-unknown-linux-gnu -Zregparm=2 -Zreg-struct-return=true +//@ compile-flags: --target i686-unknown-linux-gnu -Tregparm=2 -Treg-struct-return=true +//@ compile-flags: -Zunstable-options //@ needs-llvm-components: x86 #![feature(no_core)] diff --git a/tests/ui/target_modifiers/defaults_check.error.stderr b/tests/ui/target_modifiers/defaults_check.error.stderr index 106e64ff29356..922dc78da70aa 100644 --- a/tests/ui/target_modifiers/defaults_check.error.stderr +++ b/tests/ui/target_modifiers/defaults_check.error.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `defaults_check` +error: mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` --> $DIR/defaults_check.rs:16:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zreg-struct-return=true` in this crate is incompatible with `-Zreg-struct-return` being unset in dependency `default_reg_struct_return` - = help: unset `-Zreg-struct-return` in this crate or set `-Zreg-struct-return=true` in `default_reg_struct_return` + = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: `-Treg-struct-return=true` in this crate is incompatible with `-Treg-struct-return=false` in dependency `default_reg_struct_return` + = help: set `-Treg-struct-return=false` in this crate or `-Treg-struct-return=true` in `default_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/defaults_check.rs b/tests/ui/target_modifiers/defaults_check.rs index af42ee92a826d..b901030c0c693 100644 --- a/tests/ui/target_modifiers/defaults_check.rs +++ b/tests/ui/target_modifiers/defaults_check.rs @@ -2,19 +2,19 @@ // with the same value, explicitly specified //@ aux-build:default_reg_struct_return.rs -//@ compile-flags: --target i686-unknown-linux-gnu -Cpanic=abort +//@ compile-flags: --target i686-unknown-linux-gnu -Cpanic=abort -Zunstable-options //@ needs-llvm-components: x86 //@ revisions: ok ok_explicit error // [ok] no extra compile-flags -//@[ok_explicit] compile-flags: -Zreg-struct-return=false -//@[error] compile-flags: -Zreg-struct-return=true +//@[ok_explicit] compile-flags: -Treg-struct-return=false +//@[error] compile-flags: -Treg-struct-return=true //@[ok] check-pass //@[ok_explicit] check-pass //@ ignore-backends: gcc #![feature(no_core)] -//[error]~^ ERROR mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `defaults_check` +//[error]~^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` #![crate_type = "rlib"] #![no_core] diff --git a/tests/ui/target_modifiers/no_value_bool.error.stderr b/tests/ui/target_modifiers/no_value_bool.error.stderr index c0e3178b89cf2..f27619ed9399c 100644 --- a/tests/ui/target_modifiers/no_value_bool.error.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `no_value_bool` +error: mixing `-Treg-struct-return` will cause an ABI mismatch in crate `no_value_bool` --> $DIR/no_value_bool.rs:17:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zreg-struct-return` is unset in this crate which is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` - = help: set `-Zreg-struct-return=true` in this crate or unset `-Zreg-struct-return` in `enabled_reg_struct_return` + = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Treg-struct-return` in this crate is incompatible with `-Treg-struct-return=true` in dependency `enabled_reg_struct_return` + = help: set `-Treg-struct-return=true` in this crate or unset `-Treg-struct-return` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr index c0e3178b89cf2..e0520f4106fe0 100644 --- a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `no_value_bool` +error: mixing `-Treg-struct-return` will cause an ABI mismatch in crate `no_value_bool` --> $DIR/no_value_bool.rs:17:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zreg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zreg-struct-return` is unset in this crate which is incompatible with `-Zreg-struct-return=true` in dependency `enabled_reg_struct_return` - = help: set `-Zreg-struct-return=true` in this crate or unset `-Zreg-struct-return` in `enabled_reg_struct_return` + = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: `-Treg-struct-return=false` in this crate is incompatible with `-Treg-struct-return=true` in dependency `enabled_reg_struct_return` + = help: set `-Treg-struct-return=true` in this crate or `-Treg-struct-return=false` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/no_value_bool.rs b/tests/ui/target_modifiers/no_value_bool.rs index 46f92ead95a74..ac6fc710a4b52 100644 --- a/tests/ui/target_modifiers/no_value_bool.rs +++ b/tests/ui/target_modifiers/no_value_bool.rs @@ -2,21 +2,21 @@ // with the -Zflag specified without value (-Zflag=true is consistent with -Zflag) //@ aux-build:enabled_reg_struct_return.rs -//@ compile-flags: --target i686-unknown-linux-gnu -Cpanic=abort +//@ compile-flags: --target i686-unknown-linux-gnu -Cpanic=abort -Zunstable-options //@ needs-llvm-components: x86 //@ revisions: ok ok_explicit error error_explicit -//@[ok] compile-flags: -Zreg-struct-return -//@[ok_explicit] compile-flags: -Zreg-struct-return=true +//@[ok] compile-flags: -Treg-struct-return +//@[ok_explicit] compile-flags: -Treg-struct-return=true // [error] no extra compile-flags -//@[error_explicit] compile-flags: -Zreg-struct-return=false +//@[error_explicit] compile-flags: -Treg-struct-return=false //@[ok] check-pass //@[ok_explicit] check-pass //@ ignore-backends: gcc #![feature(no_core)] -//[error]~^ ERROR mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `no_value_bool` -//[error_explicit]~^^ ERROR mixing `-Zreg-struct-return` will cause an ABI mismatch in crate `no_value_bool` +//[error]~^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `no_value_bool` +//[error_explicit]~^^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `no_value_bool` #![crate_type = "rlib"] #![no_core] diff --git a/tests/ui/target_modifiers/two_flags.rs b/tests/ui/target_modifiers/two_flags.rs index 6c5f102458c9d..3681241358488 100644 --- a/tests/ui/target_modifiers/two_flags.rs +++ b/tests/ui/target_modifiers/two_flags.rs @@ -1,10 +1,10 @@ //@ aux-build:wrong_regparm_and_ret.rs -//@ compile-flags: --target i686-unknown-linux-gnu +//@ compile-flags: --target i686-unknown-linux-gnu -Zunstable-options //@ needs-llvm-components: x86 //@ revisions:two_allowed unknown_allowed //@[two_allowed] compile-flags: -Cunsafe-allow-abi-mismatch=regparm,reg-struct-return -//@[unknown_allowed] compile-flags: -Cunsafe-allow-abi-mismatch=unknown_flag -Zregparm=2 -Zreg-struct-return=true +//@[unknown_allowed] compile-flags: -Cunsafe-allow-abi-mismatch=unknown_flag -Tregparm=2 -Treg-struct-return=true //@[two_allowed] check-pass //@ ignore-backends: gcc From b15d841e8629119175072873a10c30c9f52f00b3 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 29 Jun 2026 12:46:04 +0000 Subject: [PATCH 12/29] sess: `-Tsanitizers{,-cfi-normalize-integers}` --- compiler/rustc_interface/src/tests.rs | 3 +- compiler/rustc_session/src/diagnostics.rs | 20 ++-- compiler/rustc_session/src/options.rs | 102 ++++++++++++++---- compiler/rustc_session/src/session.rs | 19 ++-- compiler/rustc_target/src/spec/mod.rs | 21 +++- .../sanitizer/hwasan-vs-khwasan.rs | 4 +- .../sanitizer/kcfi/emit-arity-indicator.rs | 2 +- ...arch64-shadow-call-stack-with-fixed-x18.rs | 4 +- .../cfi/add-canonical-jump-tables-flag.rs | 3 +- .../cfi/add-cfi-normalize-integers-flag.rs | 4 +- .../cfi/add-enable-split-lto-unit-flag.rs | 3 +- .../cfi/dbg-location-on-cfi-blocks.rs | 3 +- .../cfi/emit-type-checks-attr-sanitize-off.rs | 3 +- .../cfi/emit-type-checks-diag-mode.rs | 2 +- .../cfi/emit-type-checks-recover-mode.rs | 2 +- .../sanitizer/cfi/emit-type-checks.rs | 3 +- .../emit-type-metadata-attr-cfi-encoding.rs | 3 +- ...adata-id-itanium-cxx-abi-const-generics.rs | 3 +- ...tadata-id-itanium-cxx-abi-drop-in-place.rs | 3 +- ...adata-id-itanium-cxx-abi-function-types.rs | 3 +- ...e-metadata-id-itanium-cxx-abi-lifetimes.rs | 3 +- ...itanium-cxx-abi-method-secondary-typeid.rs | 3 +- ...-type-metadata-id-itanium-cxx-abi-paths.rs | 3 +- ...tadata-id-itanium-cxx-abi-pointer-types.rs | 3 +- ...data-id-itanium-cxx-abi-primitive-types.rs | 3 +- ...-itanium-cxx-abi-repr-transparent-types.rs | 3 +- ...etadata-id-itanium-cxx-abi-return-types.rs | 2 +- ...adata-id-itanium-cxx-abi-sequence-types.rs | 3 +- ...metadata-id-itanium-cxx-abi-trait-types.rs | 3 +- ...a-id-itanium-cxx-abi-user-defined-types.rs | 3 +- ...pe-metadata-itanium-cxx-abi-generalized.rs | 3 +- ...-itanium-cxx-abi-normalized-generalized.rs | 5 +- ...ype-metadata-itanium-cxx-abi-normalized.rs | 4 +- .../cfi/emit-type-metadata-itanium-cxx-abi.rs | 3 +- .../cfi/emit-type-metadata-trait-objects.rs | 3 +- .../sanitizer/cfi/external_weak_symbols.rs | 3 +- .../sanitizer/cfi/generalize-pointers.rs | 3 +- .../sanitizer/cfi/normalize-integers.rs | 4 +- .../sanitizer/hwasan-vs-khwasan.rs | 6 +- .../sanitizer/kasan-emits-instrumentation.rs | 4 +- tests/codegen-llvm/sanitizer/kasan-recover.rs | 2 +- .../kcfi/add-cfi-normalize-integers-flag.rs | 3 +- .../sanitizer/kcfi/add-kcfi-arity-flag.rs | 3 +- .../sanitizer/kcfi/add-kcfi-flag.rs | 2 +- .../sanitizer/kcfi/add-kcfi-offset-flag.rs | 3 +- ...t-kcfi-operand-bundle-attr-sanitize-off.rs | 2 +- ...rand-bundle-itanium-cxx-abi-generalized.rs | 3 +- ...-itanium-cxx-abi-normalized-generalized.rs | 3 +- ...erand-bundle-itanium-cxx-abi-normalized.rs | 3 +- ...mit-kcfi-operand-bundle-itanium-cxx-abi.rs | 2 +- .../kcfi/emit-kcfi-operand-bundle.rs | 2 +- .../kcfi/emit-type-metadata-trait-objects.rs | 3 +- .../sanitizer/kcfi/fn-ptr-reify-shim.rs | 3 +- .../sanitizer/kcfi/naked-function.rs | 3 +- .../sanitizer/khwasan-lifetime-markers.rs | 4 +- .../codegen-llvm/sanitizer/khwasan-recover.rs | 2 +- .../sanitizer/memory-track-origins.rs | 3 +- .../sanitizer/memtag-attr-check.rs | 3 +- .../sanitizer/riscv64-shadow-call-stack.rs | 3 +- .../sanitizer/sanitize-off-asan-kasan.rs | 3 +- .../sanitizer/sanitize-off-hwasan-khwasan.rs | 2 +- .../sanitizer/sanitize-off-kasan-asan.rs | 3 +- .../sanitizer/sanitize-off-khwasan-hwasan.rs | 2 +- .../sanitizer/sanitizer-recover.rs | 8 +- .../shadow-call-stack-without-fixed-x18.rs | 2 +- .../asm/global-asm-isnt-really-a-mir-body.rs | 3 +- tests/ui/sanitizer/cfg-kasan.rs | 4 +- tests/ui/sanitizer/cfg-khwasan.rs | 2 +- tests/ui/sanitizer/cfg.rs | 10 +- .../assoc-const-projection-issue-151878.rs | 2 +- tests/ui/sanitizer/cfi/async-closures.rs | 4 +- .../cfi/canonical-jump-tables-requires-cfi.rs | 2 +- .../canonical-jump-tables-requires-cfi.stderr | 2 +- tests/ui/sanitizer/cfi/closures.rs | 4 +- tests/ui/sanitizer/cfi/complex-receiver.rs | 4 +- tests/ui/sanitizer/cfi/const-generics.rs | 2 +- tests/ui/sanitizer/cfi/coroutine.rs | 4 +- tests/ui/sanitizer/cfi/drop-in-place.rs | 2 +- tests/ui/sanitizer/cfi/drop-no-principal.rs | 2 +- .../ui/sanitizer/cfi/fn-ptr-type-mismatch.rs | 4 +- tests/ui/sanitizer/cfi/fn-ptr.rs | 4 +- tests/ui/sanitizer/cfi/fn-trait-objects.rs | 2 +- .../cfi/generalize-pointers-attr-cfg.rs | 2 +- .../cfi/generalize-pointers-requires-cfi.rs | 2 +- .../generalize-pointers-requires-cfi.stderr | 2 +- .../ui/sanitizer/cfi/invalid-attr-encoding.rs | 2 +- .../is-incompatible-with-kcfi.aarch64.stderr | 2 +- .../cfi/is-incompatible-with-kcfi.rs | 4 +- .../is-incompatible-with-kcfi.x86_64.stderr | 2 +- .../cfi/normalize-integers-attr-cfg.rs | 6 +- .../cfi/normalize-integers-requires-cfi.rs | 9 +- .../normalize-integers-requires-cfi.stderr | 2 +- tests/ui/sanitizer/cfi/requires-lto.rs | 4 +- tests/ui/sanitizer/cfi/requires-lto.stderr | 2 +- tests/ui/sanitizer/cfi/self-ref.rs | 4 +- tests/ui/sanitizer/cfi/sized-associated-ty.rs | 4 +- tests/ui/sanitizer/cfi/supertraits.rs | 4 +- tests/ui/sanitizer/cfi/virtual-auto.rs | 4 +- ...-rustc-lto-requires-single-codegen-unit.rs | 6 +- ...tc-lto-requires-single-codegen-unit.stderr | 2 +- tests/ui/sanitizer/incompatible-khwasan.rs | 5 +- .../ui/sanitizer/incompatible-khwasan.stderr | 2 +- tests/ui/sanitizer/incompatible.rs | 4 +- tests/ui/sanitizer/incompatible.stderr | 2 +- ...issue-114275-cfi-const-expr-in-arry-len.rs | 2 +- .../ui/sanitizer/kcfi-arity-requires-kcfi.rs | 2 +- .../sanitizer/kcfi-arity-requires-kcfi.stderr | 2 +- tests/ui/sanitizer/kcfi-c-variadic.rs | 3 +- tests/ui/sanitizer/kcfi-mangling.rs | 3 +- tests/ui/sanitizer/kcfi/const-generics.rs | 2 +- tests/ui/sanitizer/kcfi/fn-trait-objects.rs | 2 +- .../sanitizer/unsupported-target-khwasan.rs | 2 +- tests/ui/sanitizer/unsupported-target.rs | 2 +- .../auxiliary/kcfi-normalize-ints.rs | 2 +- .../sanitizer-kcfi-normalize-ints.rs | 11 +- ...izer-kcfi-normalize-ints.wrong_flag.stderr | 8 +- ...kcfi-normalize-ints.wrong_sanitizer.stderr | 21 +++- 117 files changed, 348 insertions(+), 196 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 4b2ed08002cef..d08b93d696211 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -723,6 +723,8 @@ fn test_target_options_tracking_hash() { tracked!(regparm, Some(3)); tracked!(retpoline, true); tracked!(retpoline_external_thunk, true); + tracked!(sanitizer, SanitizerSet::CFI); + tracked!(sanitizer_cfi_normalize_integers, Some(true)); // tidy-alphabetical-end } @@ -901,7 +903,6 @@ fn test_unstable_options_tracking_hash() { tracked!(sanitizer, SanitizerSet::ADDRESS); tracked!(sanitizer_cfi_canonical_jump_tables, None); tracked!(sanitizer_cfi_generalize_pointers, Some(true)); - tracked!(sanitizer_cfi_normalize_integers, Some(true)); tracked!(sanitizer_dataflow_abilist, vec![String::from("/rustc/abc")]); tracked!(sanitizer_kcfi_arity, Some(true)); tracked!(sanitizer_memory_track_origins, 2); diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index cc1acef60e914..efe079fa95d52 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -299,9 +299,13 @@ pub(crate) struct SanitizersNotSupported { } #[derive(Diagnostic)] -#[diag("`-Zsanitizer={$first}` is incompatible with `-Zsanitizer={$second}`")] +#[diag( + "`-{$first_prefix}sanitizer={$first}` is incompatible with `-{$second_prefix}sanitizer={$second}`" +)] pub(crate) struct CannotMixAndMatchSanitizers { + pub(crate) first_prefix: &'static str, pub(crate) first: String, + pub(crate) second_prefix: &'static str, pub(crate) second: String, } @@ -318,31 +322,31 @@ pub(crate) struct CannotEnableCrtStaticLinux; pub(crate) struct CannotEnableCrtStaticPointerAuth; #[derive(Diagnostic)] -#[diag("`-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto`")] +#[diag("`-Tsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto`")] pub(crate) struct SanitizerCfiRequiresLto; #[derive(Diagnostic)] -#[diag("`-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`")] +#[diag("`-Tsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`")] pub(crate) struct SanitizerCfiRequiresSingleCodegenUnit; #[derive(Diagnostic)] -#[diag("`-Zsanitizer-cfi-canonical-jump-tables` requires `-Zsanitizer=cfi`")] +#[diag("`-Zsanitizer-cfi-canonical-jump-tables` requires `-Tsanitizer=cfi`")] pub(crate) struct SanitizerCfiCanonicalJumpTablesRequiresCfi; #[derive(Diagnostic)] -#[diag("`-Zsanitizer-cfi-generalize-pointers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi`")] +#[diag("`-Zsanitizer-cfi-generalize-pointers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi`")] pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi; #[derive(Diagnostic)] -#[diag("`-Zsanitizer-cfi-normalize-integers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi`")] +#[diag("`-Tsanitizer-cfi-normalize-integers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi`")] pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi; #[derive(Diagnostic)] -#[diag("`-Zsanitizer-kcfi-arity` requires `-Zsanitizer=kcfi`")] +#[diag("`-Zsanitizer-kcfi-arity` requires `-Tsanitizer=kcfi`")] pub(crate) struct SanitizerKcfiArityRequiresKcfi; #[derive(Diagnostic)] -#[diag("`-Z sanitizer=kcfi` requires `-C panic=abort`")] +#[diag("`-Tsanitizer=kcfi` requires `-C panic=abort`")] pub(crate) struct SanitizerKcfiRequiresPanicAbort; #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8eb8b5a40e2f4..3df8db5addefa 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -481,6 +481,12 @@ impl TargetModifierOptionValue for BranchProtection { } } +impl TargetModifierOptionValue for SanitizerSet { + fn to_string_for_diag(&self) -> String { + self.to_string() + } +} + impl TargetModifierOptionValue for Option { fn to_string_for_diag(&self) -> String { match self { @@ -768,7 +774,10 @@ mod desc { pub(crate) const parse_patchable_function_entry: &str = "a comma separated list of (prefix_nops,total_nops,section_name), (prefix_nops,total_nops), or (total_nops). Where prefix_nops <= total_nops where 0 < total_nops <= 255 and prefix_nops <= total_nops"; pub(crate) const parse_opt_panic_strategy: &str = parse_panic_strategy; pub(crate) const parse_relro_level: &str = "one of: `full`, `partial`, or `off`"; - pub(crate) const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; + pub(crate) const parse_sanitizers_all: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; + pub(crate) const parse_sanitizers_target: &str = "comma separated list of sanitizers: `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; + pub(crate) const parse_sanitizers_other: &str = + "comma separated list of sanitizers: `address`, or `leak`"; pub(crate) const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2"; pub(crate) const parse_cfguard: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`"; @@ -1237,25 +1246,59 @@ pub mod parse { true } - pub(crate) fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + enum SanitizerFilter { + All, + TargetModifiers, + NonTargetModifiers, + } + + fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>, filter: SanitizerFilter) -> bool { if let Some(v) = v { for s in v.split(',') { - *slot |= match s { - "address" => SanitizerSet::ADDRESS, - "cfi" => SanitizerSet::CFI, - "dataflow" => SanitizerSet::DATAFLOW, - "kcfi" => SanitizerSet::KCFI, - "kernel-address" => SanitizerSet::KERNELADDRESS, - "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, - "leak" => SanitizerSet::LEAK, - "memory" => SanitizerSet::MEMORY, - "memtag" => SanitizerSet::MEMTAG, - "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, - "thread" => SanitizerSet::THREAD, - "hwaddress" => SanitizerSet::HWADDRESS, - "safestack" => SanitizerSet::SAFESTACK, - "realtime" => SanitizerSet::REALTIME, - _ => return false, + match filter { + SanitizerFilter::All => { + *slot |= match s { + "address" => SanitizerSet::ADDRESS, + "cfi" => SanitizerSet::CFI, + "dataflow" => SanitizerSet::DATAFLOW, + "kcfi" => SanitizerSet::KCFI, + "kernel-address" => SanitizerSet::KERNELADDRESS, + "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, + "leak" => SanitizerSet::LEAK, + "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, + "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, + "thread" => SanitizerSet::THREAD, + "hwaddress" => SanitizerSet::HWADDRESS, + "safestack" => SanitizerSet::SAFESTACK, + "realtime" => SanitizerSet::REALTIME, + _ => return false, + } + } + SanitizerFilter::TargetModifiers => { + *slot |= match s { + "cfi" => SanitizerSet::CFI, + "dataflow" => SanitizerSet::DATAFLOW, + "kcfi" => SanitizerSet::KCFI, + "kernel-address" => SanitizerSet::KERNELADDRESS, + "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, + "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, + "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, + "thread" => SanitizerSet::THREAD, + "hwaddress" => SanitizerSet::HWADDRESS, + "safestack" => SanitizerSet::SAFESTACK, + "realtime" => SanitizerSet::REALTIME, + _ => return false, + } + } + SanitizerFilter::NonTargetModifiers => { + *slot |= match s { + "address" => SanitizerSet::ADDRESS, + "leak" => SanitizerSet::LEAK, + _ => return false, + } + } } } true @@ -1264,6 +1307,18 @@ pub mod parse { } } + pub(crate) fn parse_sanitizers_all(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + parse_sanitizers(slot, v, SanitizerFilter::All) + } + + pub(crate) fn parse_sanitizers_target(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + parse_sanitizers(slot, v, SanitizerFilter::TargetModifiers) + } + + pub(crate) fn parse_sanitizers_other(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + parse_sanitizers(slot, v, SanitizerFilter::NonTargetModifiers) + } + pub(crate) fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool { match v { Some("2") | None => { @@ -2295,6 +2350,11 @@ target_modifier_options! { retpoline_external_thunk: bool = (false, parse_bool, [TRACKED_UNSTABLE], "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ target features (default: no)"), + #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] + sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_target, [TRACKED_UNSTABLE], + "use a sanitizer"), + sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED_UNSTABLE], + "enable normalizing integer types (default: no)"), // tidy-alphabetical-end // If you add a new option, please update: @@ -2745,14 +2805,12 @@ written to standard error output)"), "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ target features (default: no)"), #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] - sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], + sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_other, [TRACKED], "use a sanitizer"), sanitizer_cfi_canonical_jump_tables: Option = (Some(true), parse_opt_bool, [TRACKED], "enable canonical jump tables (default: yes)"), sanitizer_cfi_generalize_pointers: Option = (None, parse_opt_bool, [TRACKED], "enable generalizing pointer types (default: no)"), - sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED], - "enable normalizing integer types (default: no)"), sanitizer_cfi_diag: Option = (None, parse_opt_bool, [TRACKED], "enable CFI diagnostics (default: no)"), sanitizer_cfi_recover: Option = (None, parse_opt_bool, [TRACKED], @@ -2763,7 +2821,7 @@ written to standard error output)"), "enable KCFI arity indicator (default: no)"), sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED], "enable origins tracking in MemorySanitizer"), - sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], + sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_all, [TRACKED], "enable recovery for selected sanitizers"), saturating_float_casts: Option = (None, parse_opt_bool, [TRACKED], "make float->int casts UB-free: numbers outside the integer type's range are clipped to \ diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 737d6ff17dc8c..b9269d639f9bb 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -602,7 +602,7 @@ impl Session { } pub fn is_sanitizer_cfi_normalize_integers_enabled(&self) -> bool { - self.opts.unstable_opts.sanitizer_cfi_normalize_integers == Some(true) + self.opts.target_opts.sanitizer_cfi_normalize_integers == Some(true) } pub fn is_sanitizer_kcfi_arity_enabled(&self) -> bool { @@ -1140,7 +1140,9 @@ impl Session { } pub fn sanitizers(&self) -> SanitizerSet { - return self.opts.unstable_opts.sanitizer | self.target.options.default_sanitizers; + return self.opts.target_opts.sanitizer + | self.opts.unstable_opts.sanitizer + | self.target.options.default_sanitizers; } pub fn pointer_authentication(&self) -> bool { @@ -1430,9 +1432,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } + let user_enabled_sanitizers = + sess.opts.target_opts.sanitizer | sess.opts.unstable_opts.sanitizer; // Sanitizers can only be used on platforms that we know have working sanitizer codegen. let supported_sanitizers = sess.target.options.supported_sanitizers; - let mut unsupported_sanitizers = sess.opts.unstable_opts.sanitizer - supported_sanitizers; + let mut unsupported_sanitizers = user_enabled_sanitizers - supported_sanitizers; // Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled // we should allow Shadow Call Stack sanitizer. if sess.opts.target_opts.fixed_x18 && sess.target.arch == Arch::AArch64 { @@ -1453,18 +1457,17 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } // Cannot mix and match mutually-exclusive sanitizers. - if let Some((first, second)) = sess.opts.unstable_opts.sanitizer.mutually_exclusive() { + if let Some((first, second)) = user_enabled_sanitizers.mutually_exclusive() { sess.dcx().emit_err(diagnostics::CannotMixAndMatchSanitizers { + first_prefix: first.prefix().expect("no prefix"), first: first.to_string(), + second_prefix: second.prefix().expect("no prefix"), second: second.to_string(), }); } // Cannot enable crt-static with sanitizers on Linux - if sess.crt_static(None) - && !sess.opts.unstable_opts.sanitizer.is_empty() - && !sess.target.is_like_msvc - { + if sess.crt_static(None) && !user_enabled_sanitizers.is_empty() && !sess.target.is_like_msvc { sess.dcx().emit_err(diagnostics::CannotEnableCrtStaticLinux); } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 97c8db0780733..235d06546db89 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1147,7 +1147,7 @@ impl ToJson for StackProbeType { } } -#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] +#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, Encodable, BlobDecodable, StableHash)] pub struct SanitizerSet(u16); bitflags::bitflags! { impl SanitizerSet: u16 { @@ -1229,6 +1229,25 @@ impl SanitizerSet { }) } + pub fn prefix(self) -> Option<&'static str> { + Some(match self { + SanitizerSet::ADDRESS | SanitizerSet::LEAK => "Z", + SanitizerSet::CFI + | SanitizerSet::DATAFLOW + | SanitizerSet::KCFI + | SanitizerSet::KERNELADDRESS + | SanitizerSet::KERNELHWADDRESS + | SanitizerSet::MEMORY + | SanitizerSet::MEMTAG + | SanitizerSet::SAFESTACK + | SanitizerSet::SHADOWCALLSTACK + | SanitizerSet::THREAD + | SanitizerSet::HWADDRESS + | SanitizerSet::REALTIME => "T", + _ => return None, + }) + } + pub fn mutually_exclusive(self) -> Option<(SanitizerSet, SanitizerSet)> { Self::MUTUALLY_EXCLUSIVE .into_iter() diff --git a/tests/assembly-llvm/sanitizer/hwasan-vs-khwasan.rs b/tests/assembly-llvm/sanitizer/hwasan-vs-khwasan.rs index a4362b3621326..e0393d1ae7cb8 100644 --- a/tests/assembly-llvm/sanitizer/hwasan-vs-khwasan.rs +++ b/tests/assembly-llvm/sanitizer/hwasan-vs-khwasan.rs @@ -3,9 +3,9 @@ //@ add-minicore //@ assembly-output: emit-asm //@ revisions: hwasan khwasan -//@[hwasan] compile-flags: --target aarch64-unknown-linux-gnu -Zsanitizer=hwaddress +//@[hwasan] compile-flags: --target aarch64-unknown-linux-gnu -Tsanitizer=hwaddress -Zunstable-options //@[hwasan] needs-llvm-components: aarch64 -//@[khwasan] compile-flags: --target aarch64-unknown-none -Zsanitizer=kernel-hwaddress +//@[khwasan] compile-flags: --target aarch64-unknown-none -Tsanitizer=kernel-hwaddress -Zunstable-options //@[khwasan] needs-llvm-components: aarch64 //@ compile-flags: -Copt-level=1 diff --git a/tests/assembly-llvm/sanitizer/kcfi/emit-arity-indicator.rs b/tests/assembly-llvm/sanitizer/kcfi/emit-arity-indicator.rs index ba9cabd6cef74..6776140436145 100644 --- a/tests/assembly-llvm/sanitizer/kcfi/emit-arity-indicator.rs +++ b/tests/assembly-llvm/sanitizer/kcfi/emit-arity-indicator.rs @@ -3,7 +3,7 @@ //@ add-minicore //@ revisions: x86_64 //@ assembly-output: emit-asm -//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu -Cllvm-args=-x86-asm-syntax=intel -Ctarget-feature=-crt-static -Cpanic=abort -Zsanitizer=kcfi -Zsanitizer-kcfi-arity -Copt-level=0 +//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu -Cllvm-args=-x86-asm-syntax=intel -Ctarget-feature=-crt-static -Cpanic=abort -Tsanitizer=kcfi -Zsanitizer-kcfi-arity -Copt-level=0 -Zunstable-options //@ [x86_64] needs-llvm-components: x86 #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/aarch64-shadow-call-stack-with-fixed-x18.rs b/tests/codegen-llvm/sanitizer/aarch64-shadow-call-stack-with-fixed-x18.rs index bde2bd095b779..7ec35074a5e59 100644 --- a/tests/codegen-llvm/sanitizer/aarch64-shadow-call-stack-with-fixed-x18.rs +++ b/tests/codegen-llvm/sanitizer/aarch64-shadow-call-stack-with-fixed-x18.rs @@ -1,8 +1,8 @@ //@ add-minicore //@ revisions: aarch64 android -//@[aarch64] compile-flags: --target aarch64-unknown-none -Zfixed-x18 -Zsanitizer=shadow-call-stack +//@[aarch64] compile-flags: --target aarch64-unknown-none -Tfixed-x18 -Tsanitizer=shadow-call-stack -Zunstable-options //@[aarch64] needs-llvm-components: aarch64 -//@[android] compile-flags: --target aarch64-linux-android -Zsanitizer=shadow-call-stack +//@[android] compile-flags: --target aarch64-linux-android -Tsanitizer=shadow-call-stack -Zunstable-options //@[android] needs-llvm-components: aarch64 #![allow(internal_features)] diff --git a/tests/codegen-llvm/sanitizer/cfi/add-canonical-jump-tables-flag.rs b/tests/codegen-llvm/sanitizer/cfi/add-canonical-jump-tables-flag.rs index 77857ca4ccb9e..e1c8178fdfda8 100644 --- a/tests/codegen-llvm/sanitizer/cfi/add-canonical-jump-tables-flag.rs +++ b/tests/codegen-llvm/sanitizer/cfi/add-canonical-jump-tables-flag.rs @@ -1,7 +1,8 @@ // Verifies that "CFI Canonical Jump Tables" module flag is added. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Tsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/add-cfi-normalize-integers-flag.rs b/tests/codegen-llvm/sanitizer/cfi/add-cfi-normalize-integers-flag.rs index 6cf9a72b7488d..c863c7cad0ff9 100644 --- a/tests/codegen-llvm/sanitizer/cfi/add-cfi-normalize-integers-flag.rs +++ b/tests/codegen-llvm/sanitizer/cfi/add-cfi-normalize-integers-flag.rs @@ -1,7 +1,9 @@ // Verifies that "cfi-normalize-integers" module flag is added. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Tsanitizer=cfi +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Zunstable-options +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/add-enable-split-lto-unit-flag.rs b/tests/codegen-llvm/sanitizer/cfi/add-enable-split-lto-unit-flag.rs index 0bfdbfba5d2e2..aba155e1c6123 100644 --- a/tests/codegen-llvm/sanitizer/cfi/add-enable-split-lto-unit-flag.rs +++ b/tests/codegen-llvm/sanitizer/cfi/add-enable-split-lto-unit-flag.rs @@ -1,7 +1,8 @@ // Verifies that "EnableSplitLTOUnit" module flag is added. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Tsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/dbg-location-on-cfi-blocks.rs b/tests/codegen-llvm/sanitizer/cfi/dbg-location-on-cfi-blocks.rs index 2a18e30e2b0de..18a8296bcf580 100644 --- a/tests/codegen-llvm/sanitizer/cfi/dbg-location-on-cfi-blocks.rs +++ b/tests/codegen-llvm/sanitizer/cfi/dbg-location-on-cfi-blocks.rs @@ -1,7 +1,8 @@ // Verifies that the parent block's debug information are assigned to the inserted cfi block. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -Cdebuginfo=1 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -Cdebuginfo=1 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-attr-sanitize-off.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-attr-sanitize-off.rs index c49438f43186f..7a7696765356a 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-attr-sanitize-off.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-attr-sanitize-off.rs @@ -1,7 +1,8 @@ // Verifies that pointer type membership tests for indirect calls are omitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-diag-mode.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-diag-mode.rs index 07688a8e5cb0b..1ca203e5450d4 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-diag-mode.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-diag-mode.rs @@ -1,7 +1,7 @@ // Verifies that pointer type membership tests for indirect calls are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-diag=true -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zsanitizer-cfi-diag=true -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-recover-mode.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-recover-mode.rs index 0dbcb7a833fb7..04e3015890afa 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-recover-mode.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks-recover-mode.rs @@ -1,7 +1,7 @@ // Verifies that pointer type membership tests for indirect calls are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-recover=true -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zsanitizer-cfi-recover=true -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks.rs index 9cad88f651820..959a02d22907f 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-checks.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-checks.rs @@ -1,7 +1,8 @@ // Verifies that pointer type membership tests for indirect calls are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs index cd9088f58af4a..8b71b20cd70fd 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs @@ -1,7 +1,8 @@ // Verifies that user-defined CFI encoding for types are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(cfi_encoding, extern_types)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs index 98591b0d4f1d2..321477375f185 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs @@ -2,7 +2,8 @@ // for const generics. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(adt_const_params)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs index c6e7e2771b6b8..0efea41079b90 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-drop-in-place.rs @@ -5,7 +5,8 @@ // future. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs index 047b532e994ea..4ccab646bf7f4 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs @@ -2,7 +2,8 @@ // for function types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs index 92b2ab32ea036..7a212e05f1bb8 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs @@ -2,7 +2,8 @@ // for lifetimes/regions. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(type_alias_impl_trait)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-method-secondary-typeid.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-method-secondary-typeid.rs index 5de39dc85c17e..aa06fcfdcf1c1 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-method-secondary-typeid.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-method-secondary-typeid.rs @@ -2,7 +2,8 @@ // self so they can be used as function pointers. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs index 4ce9c57070a72..9aa6c178ed279 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs @@ -2,7 +2,8 @@ // for paths. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(type_alias_impl_trait)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs index ad4fe11d08723..a8297c6b47462 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs @@ -2,7 +2,8 @@ // for pointer types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs index 93845d0519541..e05394a08846b 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs @@ -2,7 +2,8 @@ // for primitive types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs index 025aa902658ec..4cc8049247c47 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs @@ -2,7 +2,8 @@ // for repr transparent types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-return-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-return-types.rs index 74a6e2c4a1128..8bba722e82d5d 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-return-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-return-types.rs @@ -2,7 +2,7 @@ // for return types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -Cunsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -Cunsafe-allow-abi-mismatch=sanitizer -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs index 76c8150b77859..7fda98f860cc8 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs @@ -2,7 +2,8 @@ // for sequence types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs index 4fafdd2f040fc..17c6ed2ba59a8 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs @@ -2,7 +2,8 @@ // for trait types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs index 91351096ca201..c99af3e6aed75 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs @@ -2,7 +2,8 @@ // for user-defined types. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(extern_types)] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs index 22d518cca7442..99fbe0c72ec9f 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs @@ -1,7 +1,8 @@ // Verifies that generalized type metadata for functions are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-generalize-pointers -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zsanitizer-cfi-generalize-pointers -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs index 5b1aa97ab3338..c849eabeb813c 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs @@ -1,7 +1,10 @@ // Verifies that normalized and generalized type metadata for functions are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -Zsanitizer-cfi-generalize-pointers -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Zsanitizer-cfi-generalize-pointers +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs index acd72b0ca3cff..ba29d9cf37c15 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs @@ -1,7 +1,9 @@ // Verifies that normalized type metadata for functions are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Zunstable-options +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs index fa5cd471466e2..170a02976de0c 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs @@ -1,7 +1,8 @@ // Verifies that type metadata for functions are emitted. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zunstable-options +//@ compile-flags: -Tsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-trait-objects.rs b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-trait-objects.rs index 82873e935b292..800d954e504e9 100644 --- a/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-trait-objects.rs +++ b/tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-trait-objects.rs @@ -1,7 +1,8 @@ // Verifies that type metadata identifiers for trait objects are emitted correctly. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Ctarget-feature=-crt-static -Zsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Ctarget-feature=-crt-static -Tsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs b/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs index 6ac95aabae877..d90146783167b 100644 --- a/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs +++ b/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs @@ -2,7 +2,8 @@ // emitted correctly. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "bin"] #![feature(linkage)] diff --git a/tests/codegen-llvm/sanitizer/cfi/generalize-pointers.rs b/tests/codegen-llvm/sanitizer/cfi/generalize-pointers.rs index caa2f258f8f2a..14eb103046844 100644 --- a/tests/codegen-llvm/sanitizer/cfi/generalize-pointers.rs +++ b/tests/codegen-llvm/sanitizer/cfi/generalize-pointers.rs @@ -1,7 +1,8 @@ // Verifies that pointer types are generalized. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-generalize-pointers -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zsanitizer-cfi-generalize-pointers -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/cfi/normalize-integers.rs b/tests/codegen-llvm/sanitizer/cfi/normalize-integers.rs index 16f76adafb826..fe307a6c5ae0d 100644 --- a/tests/codegen-llvm/sanitizer/cfi/normalize-integers.rs +++ b/tests/codegen-llvm/sanitizer/cfi/normalize-integers.rs @@ -1,7 +1,9 @@ // Verifies that integer types are normalized. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Copt-level=0 -Zunstable-options +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/hwasan-vs-khwasan.rs b/tests/codegen-llvm/sanitizer/hwasan-vs-khwasan.rs index c34df8c3c5acd..a30d9ce71e3b9 100644 --- a/tests/codegen-llvm/sanitizer/hwasan-vs-khwasan.rs +++ b/tests/codegen-llvm/sanitizer/hwasan-vs-khwasan.rs @@ -2,11 +2,11 @@ // //@ add-minicore //@ revisions: hwasan khwasan -//@[hwasan] compile-flags: --target aarch64-unknown-linux-gnu -Zsanitizer=hwaddress +//@[hwasan] compile-flags: --target aarch64-unknown-linux-gnu -Tsanitizer=hwaddress //@[hwasan] needs-llvm-components: aarch64 -//@[khwasan] compile-flags: --target aarch64-unknown-none -Zsanitizer=kernel-hwaddress +//@[khwasan] compile-flags: --target aarch64-unknown-none -Tsanitizer=kernel-hwaddress //@[khwasan] needs-llvm-components: aarch64 -//@ compile-flags: -Copt-level=0 +//@ compile-flags: -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items, sanitize)] diff --git a/tests/codegen-llvm/sanitizer/kasan-emits-instrumentation.rs b/tests/codegen-llvm/sanitizer/kasan-emits-instrumentation.rs index f0135cdd00115..6b713d877ab73 100644 --- a/tests/codegen-llvm/sanitizer/kasan-emits-instrumentation.rs +++ b/tests/codegen-llvm/sanitizer/kasan-emits-instrumentation.rs @@ -1,7 +1,7 @@ -// Verifies that `-Zsanitizer=kernel-address` emits sanitizer instrumentation. +// Verifies that `-Tsanitizer=kernel-address` emits sanitizer instrumentation. //@ add-minicore -//@ compile-flags: -Zsanitizer=kernel-address -Copt-level=0 +//@ compile-flags: -Tsanitizer=kernel-address -Copt-level=0 -Zunstable-options //@ revisions: aarch64 aarch64v8r riscv64imac riscv64gc x86_64 //@[aarch64] compile-flags: --target aarch64-unknown-none //@[aarch64] needs-llvm-components: aarch64 diff --git a/tests/codegen-llvm/sanitizer/kasan-recover.rs b/tests/codegen-llvm/sanitizer/kasan-recover.rs index f0f9180ae595e..1ad292356b81a 100644 --- a/tests/codegen-llvm/sanitizer/kasan-recover.rs +++ b/tests/codegen-llvm/sanitizer/kasan-recover.rs @@ -5,7 +5,7 @@ //@ revisions: KASAN KASAN-RECOVER //@ compile-flags: -Copt-level=0 //@ needs-llvm-components: x86 -//@ compile-flags: -Zsanitizer=kernel-address --target x86_64-unknown-none +//@ compile-flags: -Tsanitizer=kernel-address --target x86_64-unknown-none -Zunstable-options //@[KASAN-RECOVER] compile-flags: -Zsanitizer-recover=kernel-address #![feature(no_core, sanitize, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/add-cfi-normalize-integers-flag.rs b/tests/codegen-llvm/sanitizer/kcfi/add-cfi-normalize-integers-flag.rs index 53b8c605eb73b..b779633f7a60f 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/add-cfi-normalize-integers-flag.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/add-cfi-normalize-integers-flag.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers +//@ compile-flags: -Ctarget-feature=-crt-static -Tsanitizer=kcfi -Tsanitizer-cfi-normalize-integers +//@ compile-flags: -Zunstable-options #![feature(no_core, lang_items)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-arity-flag.rs b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-arity-flag.rs index 7a0e3b1da2506..ae8053627ad85 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-arity-flag.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-arity-flag.rs @@ -4,7 +4,8 @@ //@ revisions: x86_64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Cpanic=abort -Zsanitizer=kcfi -Zsanitizer-kcfi-arity +//@ compile-flags: -Ctarget-feature=-crt-static -Cpanic=abort -Tsanitizer=kcfi -Zsanitizer-kcfi-arity +//@ compile-flags: -Zunstable-options #![feature(no_core, lang_items)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-flag.rs b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-flag.rs index 9058d5b5cfcb9..ed1fa424bf471 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-flag.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-flag.rs @@ -8,7 +8,7 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi +//@ compile-flags: -Ctarget-feature=-crt-static -Tsanitizer=kcfi -Zunstable-options #![feature(no_core, lang_items)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-offset-flag.rs b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-offset-flag.rs index 6574302033c82..0f08ec6251a23 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-offset-flag.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/add-kcfi-offset-flag.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Z patchable-function-entry=4,3 +//@ compile-flags: -Ctarget-feature=-crt-static -Tsanitizer=kcfi -Z patchable-function-entry=4,3 +//@ compile-flags: -Zunstable-options #![feature(no_core, lang_items, patchable_function_entry)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-sanitize-off.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-sanitize-off.rs index eb9ab6b8f90cb..eec81a1c5c983 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-sanitize-off.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-sanitize-off.rs @@ -8,7 +8,7 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0 +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(no_core, sanitize, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs index f934a3bfcee76..b5a2ba1acb6e6 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-generalize-pointers +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Zsanitizer-cfi-generalize-pointers +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs index b72b6d7ce308e..79b42ef837a7e 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zsanitizer-cfi-generalize-pointers +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Tsanitizer-cfi-normalize-integers +//@ compile-flags: -Zsanitizer-cfi-generalize-pointers -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs index 064ab53a18561..e950259cb4300 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Tsanitizer-cfi-normalize-integers +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs index 8410286e49dbf..937ee5d787bb4 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs @@ -8,7 +8,7 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0 +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle.rs index 3494854bcffd3..74cefcc5a69f6 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle.rs @@ -8,7 +8,7 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0 +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/emit-type-metadata-trait-objects.rs b/tests/codegen-llvm/sanitizer/kcfi/emit-type-metadata-trait-objects.rs index 7d71be8e33d80..29fb0cca5d842 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/emit-type-metadata-trait-objects.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/emit-type-metadata-trait-objects.rs @@ -8,7 +8,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi -Copt-level=0 +//@ compile-flags: -Cno-prepopulate-passes -Tsanitizer=kcfi -Copt-level=0 +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] #![feature(arbitrary_self_types, no_core, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs b/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs index 8cfb6a57a4a97..f2a6afc0855e9 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/fn-ptr-reify-shim.rs @@ -6,7 +6,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Cno-prepopulate-passes -Copt-level=0 +//@ compile-flags: -Ctarget-feature=-crt-static -Tsanitizer=kcfi -Cno-prepopulate-passes -Copt-level=0 +//@ compile-flags: -Zunstable-options #![feature(no_core, lang_items)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs b/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs index 6b9d11b192b33..922976152bb68 100644 --- a/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs +++ b/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs @@ -6,7 +6,8 @@ //@ [aarch64v8r] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Cno-prepopulate-passes -Copt-level=0 +//@ compile-flags: -Ctarget-feature=-crt-static -Tsanitizer=kcfi -Cno-prepopulate-passes -Copt-level=0 +//@ compile-flags: -Zunstable-options #![feature(no_core, lang_items)] #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/khwasan-lifetime-markers.rs b/tests/codegen-llvm/sanitizer/khwasan-lifetime-markers.rs index 26dc7983d7314..1e81e33b8ab20 100644 --- a/tests/codegen-llvm/sanitizer/khwasan-lifetime-markers.rs +++ b/tests/codegen-llvm/sanitizer/khwasan-lifetime-markers.rs @@ -1,7 +1,7 @@ -// Verifies that `-Zsanitizer=kernel-hwaddress` enables lifetime markers. +// Verifies that `-Tsanitizer=kernel-hwaddress` enables lifetime markers. //@ add-minicore -//@ compile-flags: -Zsanitizer=kernel-hwaddress -Copt-level=0 +//@ compile-flags: -Tsanitizer=kernel-hwaddress -Copt-level=0 -Zunstable-options //@ compile-flags: --target aarch64-unknown-none //@ needs-llvm-components: aarch64 diff --git a/tests/codegen-llvm/sanitizer/khwasan-recover.rs b/tests/codegen-llvm/sanitizer/khwasan-recover.rs index 452a0f579fc72..069b7a066bbbe 100644 --- a/tests/codegen-llvm/sanitizer/khwasan-recover.rs +++ b/tests/codegen-llvm/sanitizer/khwasan-recover.rs @@ -6,7 +6,7 @@ //@ revisions: KHWASAN KHWASAN-RECOVER //@ no-prefer-dynamic //@ compile-flags: -Copt-level=0 -//@ compile-flags: -Zsanitizer=kernel-hwaddress --target aarch64-unknown-none +//@ compile-flags: -Tsanitizer=kernel-hwaddress --target aarch64-unknown-none -Zunstable-options //@[KHWASAN-RECOVER] compile-flags: -Zsanitizer-recover=kernel-hwaddress #![feature(no_core, sanitize, lang_items)] diff --git a/tests/codegen-llvm/sanitizer/memory-track-origins.rs b/tests/codegen-llvm/sanitizer/memory-track-origins.rs index a72e523c4e193..526ff0684acf8 100644 --- a/tests/codegen-llvm/sanitizer/memory-track-origins.rs +++ b/tests/codegen-llvm/sanitizer/memory-track-origins.rs @@ -4,7 +4,8 @@ //@ needs-sanitizer-memory //@ revisions:MSAN-0 MSAN-1 MSAN-2 MSAN-1-LTO MSAN-2-LTO // -//@ compile-flags: -Zsanitizer=memory -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Tsanitizer=memory -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options // [MSAN-0] no extra compile-flags //@[MSAN-1] compile-flags: -Zsanitizer-memory-track-origins=1 //@[MSAN-2] compile-flags: -Zsanitizer-memory-track-origins diff --git a/tests/codegen-llvm/sanitizer/memtag-attr-check.rs b/tests/codegen-llvm/sanitizer/memtag-attr-check.rs index fc430f3a57003..e70e99549214d 100644 --- a/tests/codegen-llvm/sanitizer/memtag-attr-check.rs +++ b/tests/codegen-llvm/sanitizer/memtag-attr-check.rs @@ -2,7 +2,8 @@ // applied when enabling the memtag sanitizer. // //@ needs-sanitizer-memtag -//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer -Zsanitizer=memtag -Ctarget-feature=+mte -Copt-level=0 +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer -Tsanitizer=memtag -Ctarget-feature=+mte -Copt-level=0 +//@ compile-flags: -Zunstable-options #![crate_type = "lib"] diff --git a/tests/codegen-llvm/sanitizer/riscv64-shadow-call-stack.rs b/tests/codegen-llvm/sanitizer/riscv64-shadow-call-stack.rs index 72f9c12fae0e2..ab4c4818839f5 100644 --- a/tests/codegen-llvm/sanitizer/riscv64-shadow-call-stack.rs +++ b/tests/codegen-llvm/sanitizer/riscv64-shadow-call-stack.rs @@ -1,5 +1,6 @@ //@ add-minicore -//@ compile-flags: --target riscv64imac-unknown-none-elf -Zsanitizer=shadow-call-stack +//@ compile-flags: --target riscv64imac-unknown-none-elf -Tsanitizer=shadow-call-stack +//@ compile-flags: -Zunstable-options //@ needs-llvm-components: riscv #![allow(internal_features)] diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-asan-kasan.rs b/tests/codegen-llvm/sanitizer/sanitize-off-asan-kasan.rs index cef4a650e4775..7c605837d5342 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-asan-kasan.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-asan-kasan.rs @@ -2,7 +2,8 @@ // the kernel address sanitizer. // //@ add-minicore -//@ compile-flags: -Zsanitizer=kernel-address -Ctarget-feature=-crt-static -Copt-level=0 +//@ compile-flags: -Tsanitizer=kernel-address -Ctarget-feature=-crt-static -Copt-level=0 +//@ compile-flags: -Zunstable-options //@ revisions: aarch64 aarch64v8r riscv64imac riscv64gc x86_64 //@[aarch64] compile-flags: --target aarch64-unknown-none //@[aarch64] needs-llvm-components: aarch64 diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-hwasan-khwasan.rs b/tests/codegen-llvm/sanitizer/sanitize-off-hwasan-khwasan.rs index 313f48031e4ab..37b7e6bf65d73 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-hwasan-khwasan.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-hwasan-khwasan.rs @@ -2,7 +2,7 @@ // the kernel hardware-assisted address sanitizer. // //@ add-minicore -//@ compile-flags: -Zsanitizer=kernel-hwaddress --target aarch64-unknown-none +//@ compile-flags: -Tsanitizer=kernel-hwaddress --target aarch64-unknown-none -Zunstable-options //@ compile-flags: -Ctarget-feature=-crt-static -Copt-level=0 //@ needs-llvm-components: aarch64 diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs b/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs index 61ad0ba7d90d3..873412a8d1894 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs @@ -2,7 +2,8 @@ // the address sanitizer. // //@ needs-sanitizer-address -//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-khwasan-hwasan.rs b/tests/codegen-llvm/sanitizer/sanitize-off-khwasan-hwasan.rs index a4491eb9f785d..4d2f5b338befa 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-khwasan-hwasan.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-khwasan-hwasan.rs @@ -4,7 +4,7 @@ //@ needs-sanitizer-hwaddress //@ compile-flags: -Cunsafe-allow-abi-mismatch=sanitizer //@ compile-flags: -Ctarget-feature=-crt-static -//@ compile-flags: -Zsanitizer=hwaddress -Copt-level=0 +//@ compile-flags: -Tsanitizer=hwaddress -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/sanitizer-recover.rs b/tests/codegen-llvm/sanitizer/sanitizer-recover.rs index 5e05b92f3b100..951a7934bab33 100644 --- a/tests/codegen-llvm/sanitizer/sanitizer-recover.rs +++ b/tests/codegen-llvm/sanitizer/sanitizer-recover.rs @@ -9,9 +9,11 @@ //@ compile-flags: -Ctarget-feature=-crt-static //@[ASAN] compile-flags: -Zsanitizer=address -Copt-level=0 //@[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address -Copt-level=0 -//@[MSAN] compile-flags: -Zsanitizer=memory -//@[MSAN-RECOVER] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -//@[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -C lto=fat +//@[MSAN] compile-flags: -Tsanitizer=memory -Zunstable-options +//@[MSAN-RECOVER] compile-flags: -Tsanitizer=memory -Zsanitizer-recover=memory +//@[MSAN-RECOVER] compile-flags: -Zunstable-options +//@[MSAN-RECOVER-LTO] compile-flags: -Tsanitizer=memory -Zsanitizer-recover=memory -C lto=fat +//@[MSAN-RECOVER-LTO] compile-flags: -Zunstable-options // // MSAN-NOT: @__msan_keep_going // MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}}constant i32 1 diff --git a/tests/ui/abi/shadow-call-stack-without-fixed-x18.rs b/tests/ui/abi/shadow-call-stack-without-fixed-x18.rs index 824327ad06d36..6ff14fa61a75f 100644 --- a/tests/ui/abi/shadow-call-stack-without-fixed-x18.rs +++ b/tests/ui/abi/shadow-call-stack-without-fixed-x18.rs @@ -1,4 +1,4 @@ -//@ compile-flags: --target aarch64-unknown-none -Zsanitizer=shadow-call-stack +//@ compile-flags: --target aarch64-unknown-none -Tsanitizer=shadow-call-stack -Zunstable-options //@ dont-check-compiler-stderr //@ needs-llvm-components: aarch64 //@ ignore-backends: gcc diff --git a/tests/ui/asm/global-asm-isnt-really-a-mir-body.rs b/tests/ui/asm/global-asm-isnt-really-a-mir-body.rs index 94dab4235e093..2a10764faa605 100644 --- a/tests/ui/asm/global-asm-isnt-really-a-mir-body.rs +++ b/tests/ui/asm/global-asm-isnt-really-a-mir-body.rs @@ -10,7 +10,8 @@ //@[instrument] only-linux // Make sure we don't try to CFI encode it. -//@[cfi] compile-flags: -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Clink-dead-code=true +//@[cfi] compile-flags: -Tsanitizer=cfi -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Clink-dead-code=true +//@[cfi] compile-flags: -Zunstable-options //@[cfi] needs-sanitizer-cfi //@[cfi] no-prefer-dynamic // FIXME(#122848) Remove only-linux once OSX CFI binaries work diff --git a/tests/ui/sanitizer/cfg-kasan.rs b/tests/ui/sanitizer/cfg-kasan.rs index 2d934357adfe0..e505ffab0ee04 100644 --- a/tests/ui/sanitizer/cfg-kasan.rs +++ b/tests/ui/sanitizer/cfg-kasan.rs @@ -1,9 +1,9 @@ -// Verifies that when compiling with -Zsanitizer=kernel-address, +// Verifies that when compiling with -Tsanitizer=kernel-address, // the `#[cfg(sanitize = "address")]` attribute is configured. //@ add-minicore //@ check-pass -//@ compile-flags: -Zsanitizer=kernel-address +//@ compile-flags: -Tsanitizer=kernel-address -Zunstable-options //@ revisions: aarch64 riscv64imac riscv64gc x86_64 //@[aarch64] compile-flags: --target aarch64-unknown-none //@[aarch64] needs-llvm-components: aarch64 diff --git a/tests/ui/sanitizer/cfg-khwasan.rs b/tests/ui/sanitizer/cfg-khwasan.rs index 27a2f6030d0ba..d3f5fa415f247 100644 --- a/tests/ui/sanitizer/cfg-khwasan.rs +++ b/tests/ui/sanitizer/cfg-khwasan.rs @@ -3,7 +3,7 @@ //@ add-minicore //@ check-pass -//@ compile-flags: -Zsanitizer=kernel-hwaddress --target aarch64-unknown-none +//@ compile-flags: -Tsanitizer=kernel-hwaddress --target aarch64-unknown-none -Zunstable-options //@ needs-llvm-components: aarch64 //@ ignore-backends: gcc diff --git a/tests/ui/sanitizer/cfg.rs b/tests/ui/sanitizer/cfg.rs index 70914dcf93617..d135acb8c23a8 100644 --- a/tests/ui/sanitizer/cfg.rs +++ b/tests/ui/sanitizer/cfg.rs @@ -8,21 +8,21 @@ //@[address]needs-sanitizer-address //@[address]compile-flags: -Zsanitizer=address //@[cfi]needs-sanitizer-cfi -//@[cfi]compile-flags: -Zsanitizer=cfi +//@[cfi]compile-flags: -Tsanitizer=cfi -Zunstable-options //@[cfi]compile-flags: -Clto -Ccodegen-units=1 //@[kcfi]needs-llvm-components: x86 -//@[kcfi]compile-flags: -Zsanitizer=kcfi --target x86_64-unknown-none +//@[kcfi]compile-flags: -Tsanitizer=kcfi --target x86_64-unknown-none -Zunstable-options //@[kcfi]compile-flags: -C panic=abort //@[leak]needs-sanitizer-leak //@[leak]compile-flags: -Zsanitizer=leak //@[memory]needs-sanitizer-memory -//@[memory]compile-flags: -Zsanitizer=memory +//@[memory]compile-flags: -Tsanitizer=memory -Zunstable-options //@[thread]needs-sanitizer-thread -//@[thread]compile-flags: -Zsanitizer=thread +//@[thread]compile-flags: -Tsanitizer=thread -Zunstable-options //@ ignore-backends: gcc #![feature(cfg_sanitize, no_core)] -#![crate_type="lib"] +#![crate_type = "lib"] #![no_core] extern crate minicore; diff --git a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs index 3fd33c7c1bb67..3e7fe04acc6d1 100644 --- a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs +++ b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Zsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer -Ccodegen-units=1 -Clto +//@ compile-flags: -Tsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer -Ccodegen-units=1 -Clto -Zunstable-options //@ needs-rustc-debug-assertions //@ needs-sanitizer-cfi //@ build-pass diff --git a/tests/ui/sanitizer/cfi/async-closures.rs b/tests/ui/sanitizer/cfi/async-closures.rs index 621a0882c91b2..e39af75e8fd57 100644 --- a/tests/ui/sanitizer/cfi/async-closures.rs +++ b/tests/ui/sanitizer/cfi/async-closures.rs @@ -9,8 +9,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -Z panic-abort-tests -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.rs b/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.rs index 36f6e3bc95e18..beb85dbddda3e 100644 --- a/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.rs +++ b/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.rs @@ -7,4 +7,4 @@ #![no_core] #![no_main] -//~? ERROR `-Zsanitizer-cfi-canonical-jump-tables` requires `-Zsanitizer=cfi` +//~? ERROR `-Zsanitizer-cfi-canonical-jump-tables` requires `-Tsanitizer=cfi` diff --git a/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.stderr b/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.stderr index de67d6a6b7f06..5ce1755f0eb5c 100644 --- a/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.stderr +++ b/tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer-cfi-canonical-jump-tables` requires `-Zsanitizer=cfi` +error: `-Zsanitizer-cfi-canonical-jump-tables` requires `-Tsanitizer=cfi` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/cfi/closures.rs b/tests/ui/sanitizer/cfi/closures.rs index 7493dba4928b0..df4bd24336251 100644 --- a/tests/ui/sanitizer/cfi/closures.rs +++ b/tests/ui/sanitizer/cfi/closures.rs @@ -8,8 +8,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -Z panic-abort-tests -C prefer-dynamic=off //@ compile-flags: --test //@ run-pass diff --git a/tests/ui/sanitizer/cfi/complex-receiver.rs b/tests/ui/sanitizer/cfi/complex-receiver.rs index adacc0d6c5df7..d0eb1ab38a31a 100644 --- a/tests/ui/sanitizer/cfi/complex-receiver.rs +++ b/tests/ui/sanitizer/cfi/complex-receiver.rs @@ -10,8 +10,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/const-generics.rs b/tests/ui/sanitizer/cfi/const-generics.rs index 42fff233dd84b..116f2d828cc69 100644 --- a/tests/ui/sanitizer/cfi/const-generics.rs +++ b/tests/ui/sanitizer/cfi/const-generics.rs @@ -5,7 +5,7 @@ // FIXME(#122848) Remove only-linux once OSX CFI binaries work //@ only-linux //@ ignore-backends: gcc -//@ compile-flags: -Ctarget-feature=-crt-static -Ccodegen-units=1 -Clto -Cprefer-dynamic=off -Copt-level=0 -Zsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Ctarget-feature=-crt-static -Ccodegen-units=1 -Clto -Cprefer-dynamic=off -Copt-level=0 -Tsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer -Zunstable-options //@ run-pass #![feature(adt_const_params)] diff --git a/tests/ui/sanitizer/cfi/coroutine.rs b/tests/ui/sanitizer/cfi/coroutine.rs index d85615b597de2..fca40cb9662e0 100644 --- a/tests/ui/sanitizer/cfi/coroutine.rs +++ b/tests/ui/sanitizer/cfi/coroutine.rs @@ -10,8 +10,8 @@ //@ compile-flags: -C target-feature=-crt-static //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -Z panic-abort-tests -C prefer-dynamic=off //@ compile-flags: --test //@ run-pass diff --git a/tests/ui/sanitizer/cfi/drop-in-place.rs b/tests/ui/sanitizer/cfi/drop-in-place.rs index fe59d54631248..f23186454be96 100644 --- a/tests/ui/sanitizer/cfi/drop-in-place.rs +++ b/tests/ui/sanitizer/cfi/drop-in-place.rs @@ -4,7 +4,7 @@ //@ only-linux //@ ignore-backends: gcc //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Copt-level=0 -Cprefer-dynamic=off -Ctarget-feature=-crt-static -Zsanitizer=cfi +//@ compile-flags: -Clto -Copt-level=0 -Cprefer-dynamic=off -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zunstable-options //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer //@ run-pass diff --git a/tests/ui/sanitizer/cfi/drop-no-principal.rs b/tests/ui/sanitizer/cfi/drop-no-principal.rs index 4fb905eb51d05..ab51defa9239b 100644 --- a/tests/ui/sanitizer/cfi/drop-no-principal.rs +++ b/tests/ui/sanitizer/cfi/drop-no-principal.rs @@ -4,7 +4,7 @@ // FIXME(#122848) Remove only-linux once OSX CFI binaries works //@ only-linux //@ ignore-backends: gcc -//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Tsanitizer=cfi -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options //@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0 // FIXME(#118761) Should be run-pass once the labels on drop are compatible. // This test is being landed ahead of that to test that the compiler doesn't ICE while labeling the diff --git a/tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs b/tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs index 6fe7eec7c6920..d28c1eccec38f 100644 --- a/tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs +++ b/tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs @@ -12,9 +12,9 @@ //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C opt-level=0 -C codegen-units=1 -C lto //@ [cfi] compile-flags: -C prefer-dynamic=off -//@ [cfi] compile-flags: -Z sanitizer=cfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options //@ [cfi] compile-flags: -Z sanitizer-cfi-diag=true -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-fail-or-crash diff --git a/tests/ui/sanitizer/cfi/fn-ptr.rs b/tests/ui/sanitizer/cfi/fn-ptr.rs index bdb8c7ceb328c..acf9066559cf6 100644 --- a/tests/ui/sanitizer/cfi/fn-ptr.rs +++ b/tests/ui/sanitizer/cfi/fn-ptr.rs @@ -10,8 +10,8 @@ //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C opt-level=0 -C codegen-units=1 -C lto //@ [cfi] compile-flags: -C prefer-dynamic=off -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/fn-trait-objects.rs b/tests/ui/sanitizer/cfi/fn-trait-objects.rs index 977d4124fff0c..5cfda443c6016 100644 --- a/tests/ui/sanitizer/cfi/fn-trait-objects.rs +++ b/tests/ui/sanitizer/cfi/fn-trait-objects.rs @@ -4,7 +4,7 @@ //@ needs-sanitizer-cfi //@ only-linux //@ ignore-backends: gcc -//@ compile-flags: -Ctarget-feature=-crt-static -Ccodegen-units=1 -Clto -Cprefer-dynamic=off -Copt-level=0 -Zsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer --test +//@ compile-flags: -Ctarget-feature=-crt-static -Ccodegen-units=1 -Clto -Cprefer-dynamic=off -Copt-level=0 -Tsanitizer=cfi -Cunsafe-allow-abi-mismatch=sanitizer -Zunstable-options --test //@ run-pass #![feature(fn_traits)] diff --git a/tests/ui/sanitizer/cfi/generalize-pointers-attr-cfg.rs b/tests/ui/sanitizer/cfi/generalize-pointers-attr-cfg.rs index 44cdcb250e701..71433913adefd 100644 --- a/tests/ui/sanitizer/cfi/generalize-pointers-attr-cfg.rs +++ b/tests/ui/sanitizer/cfi/generalize-pointers-attr-cfg.rs @@ -3,7 +3,7 @@ // //@ needs-sanitizer-cfi //@ check-pass -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-generalize-pointers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zsanitizer-cfi-generalize-pointers -Zunstable-options //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer #![feature(cfg_sanitizer_cfi)] diff --git a/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.rs b/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.rs index 83277da528c96..6b7c06b162963 100644 --- a/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.rs +++ b/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.rs @@ -8,4 +8,4 @@ #![no_core] #![no_main] -//~? ERROR `-Zsanitizer-cfi-generalize-pointers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi` +//~? ERROR `-Zsanitizer-cfi-generalize-pointers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi` diff --git a/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.stderr b/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.stderr index 621708de241c2..1145b0bb4b34d 100644 --- a/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.stderr +++ b/tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer-cfi-generalize-pointers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi` +error: `-Zsanitizer-cfi-generalize-pointers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/cfi/invalid-attr-encoding.rs b/tests/ui/sanitizer/cfi/invalid-attr-encoding.rs index 23ffabad62fe8..3ac5c337a2a39 100644 --- a/tests/ui/sanitizer/cfi/invalid-attr-encoding.rs +++ b/tests/ui/sanitizer/cfi/invalid-attr-encoding.rs @@ -1,7 +1,7 @@ // Verifies that invalid user-defined CFI encodings can't be used. // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zunstable-options #![feature(cfi_encoding, no_core)] #![no_core] diff --git a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.aarch64.stderr b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.aarch64.stderr index 7f596a19104e6..2183592ebaacc 100644 --- a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.aarch64.stderr +++ b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.aarch64.stderr @@ -1,6 +1,6 @@ error: cfi sanitizer is not supported for this target -error: `-Zsanitizer=cfi` is incompatible with `-Zsanitizer=kcfi` +error: `-Tsanitizer=cfi` is incompatible with `-Tsanitizer=kcfi` error: aborting due to 2 previous errors diff --git a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.rs b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.rs index 71cae90743078..c4fa8006536c4 100644 --- a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.rs +++ b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.rs @@ -5,7 +5,7 @@ //@ [aarch64] needs-llvm-components: aarch64 //@ [x86_64] compile-flags: --target x86_64-unknown-none //@ [x86_64] needs-llvm-components: x86 -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer=kcfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Tsanitizer=kcfi -Zunstable-options //@ ignore-backends: gcc #![feature(no_core)] @@ -13,4 +13,4 @@ #![no_main] //~? ERROR cfi sanitizer is not supported for this target -//~? ERROR `-Zsanitizer=cfi` is incompatible with `-Zsanitizer=kcfi` +//~? ERROR `-Tsanitizer=cfi` is incompatible with `-Tsanitizer=kcfi` diff --git a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.x86_64.stderr b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.x86_64.stderr index 7f596a19104e6..2183592ebaacc 100644 --- a/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.x86_64.stderr +++ b/tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.x86_64.stderr @@ -1,6 +1,6 @@ error: cfi sanitizer is not supported for this target -error: `-Zsanitizer=cfi` is incompatible with `-Zsanitizer=kcfi` +error: `-Tsanitizer=cfi` is incompatible with `-Tsanitizer=kcfi` error: aborting due to 2 previous errors diff --git a/tests/ui/sanitizer/cfi/normalize-integers-attr-cfg.rs b/tests/ui/sanitizer/cfi/normalize-integers-attr-cfg.rs index ce4e31eb69b5a..8de9fb572a30f 100644 --- a/tests/ui/sanitizer/cfi/normalize-integers-attr-cfg.rs +++ b/tests/ui/sanitizer/cfi/normalize-integers-attr-cfg.rs @@ -1,9 +1,11 @@ -// Verifies that when compiling with `-Zsanitizer-cfi-normalize-integers` the +// Verifies that when compiling with `-Tsanitizer-cfi-normalize-integers` the // `#[cfg(sanitizer_cfi_normalize_integers)]` attribute is configured. // //@ needs-sanitizer-cfi //@ check-pass -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Zunstable-options +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer,sanitizer-cfi-normalize-integers #![feature(cfg_sanitizer_cfi)] diff --git a/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.rs b/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.rs index b9d5b9623d5f0..3f6175a1ba541 100644 --- a/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.rs +++ b/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.rs @@ -1,11 +1,12 @@ -// Verifies that `-Zsanitizer-cfi-normalize-integers` requires `-Zsanitizer=cfi` or -// `-Zsanitizer=kcfi` +// Verifies that `-Tsanitizer-cfi-normalize-integers` requires `-Tsanitizer=cfi` or +// `-Tsanitizer=kcfi` // //@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer-cfi-normalize-integers +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static +//@ compile-flags: -Tsanitizer-cfi-normalize-integers -Zunstable-options #![feature(no_core)] #![no_core] #![no_main] -//~? ERROR `-Zsanitizer-cfi-normalize-integers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi` +//~? ERROR `-Tsanitizer-cfi-normalize-integers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi` diff --git a/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.stderr b/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.stderr index 748fb60dad92e..b253ded6b4ed0 100644 --- a/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.stderr +++ b/tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer-cfi-normalize-integers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi` +error: `-Tsanitizer-cfi-normalize-integers` requires `-Tsanitizer=cfi` or `-Tsanitizer=kcfi` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/cfi/requires-lto.rs b/tests/ui/sanitizer/cfi/requires-lto.rs index db83f5f6bf020..0e0fcb8e0a9c8 100644 --- a/tests/ui/sanitizer/cfi/requires-lto.rs +++ b/tests/ui/sanitizer/cfi/requires-lto.rs @@ -1,10 +1,10 @@ // Verifies that `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto`. // //@ needs-sanitizer-cfi -//@ compile-flags: -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi +//@ compile-flags: -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zunstable-options #![feature(no_core)] #![no_core] #![no_main] -//~? ERROR `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto` +//~? ERROR `-Tsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto` diff --git a/tests/ui/sanitizer/cfi/requires-lto.stderr b/tests/ui/sanitizer/cfi/requires-lto.stderr index efc0c43138e12..2238d0ac5dfd5 100644 --- a/tests/ui/sanitizer/cfi/requires-lto.stderr +++ b/tests/ui/sanitizer/cfi/requires-lto.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto` +error: `-Tsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/cfi/self-ref.rs b/tests/ui/sanitizer/cfi/self-ref.rs index 827610a261064..d1100d98b2be9 100644 --- a/tests/ui/sanitizer/cfi/self-ref.rs +++ b/tests/ui/sanitizer/cfi/self-ref.rs @@ -8,8 +8,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/sized-associated-ty.rs b/tests/ui/sanitizer/cfi/sized-associated-ty.rs index da8c385c6fc8b..28e0305e901f0 100644 --- a/tests/ui/sanitizer/cfi/sized-associated-ty.rs +++ b/tests/ui/sanitizer/cfi/sized-associated-ty.rs @@ -9,8 +9,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/supertraits.rs b/tests/ui/sanitizer/cfi/supertraits.rs index b2782dff5d555..a0953732b1d6a 100644 --- a/tests/ui/sanitizer/cfi/supertraits.rs +++ b/tests/ui/sanitizer/cfi/supertraits.rs @@ -8,8 +8,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/virtual-auto.rs b/tests/ui/sanitizer/cfi/virtual-auto.rs index d3a715c079aa6..dee3b612e0c23 100644 --- a/tests/ui/sanitizer/cfi/virtual-auto.rs +++ b/tests/ui/sanitizer/cfi/virtual-auto.rs @@ -8,8 +8,8 @@ //@ [kcfi] needs-sanitizer-kcfi //@ compile-flags: -C target-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer //@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0 -//@ [cfi] compile-flags: -Z sanitizer=cfi -//@ [kcfi] compile-flags: -Z sanitizer=kcfi +//@ [cfi] compile-flags: -T sanitizer=cfi -Z unstable-options +//@ [kcfi] compile-flags: -T sanitizer=kcfi -Z unstable-options //@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off //@ run-pass diff --git a/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.rs b/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.rs index 4ef5b6756a495..c468efbd37ac5 100644 --- a/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.rs +++ b/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.rs @@ -1,10 +1,10 @@ -// Verifies that `-Zsanitizer=cfi` with `-Clto` or `-Clto=thin` requires `-Ccodegen-units=1`. +// Verifies that `-Tsanitizer=cfi` with `-Clto` or `-Clto=thin` requires `-Ccodegen-units=1`. // //@ needs-sanitizer-cfi -//@ compile-flags: -Ccodegen-units=2 -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi +//@ compile-flags: -Ccodegen-units=2 -Clto -Ctarget-feature=-crt-static -Tsanitizer=cfi -Zunstable-options #![feature(no_core)] #![no_core] #![no_main] -//~? ERROR `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1` +//~? ERROR `-Tsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1` diff --git a/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.stderr b/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.stderr index 8d6dc1d8f1ea4..17baa86534e0b 100644 --- a/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.stderr +++ b/tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1` +error: `-Tsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/incompatible-khwasan.rs b/tests/ui/sanitizer/incompatible-khwasan.rs index eb6a5d33a472b..be7b1d4d57837 100644 --- a/tests/ui/sanitizer/incompatible-khwasan.rs +++ b/tests/ui/sanitizer/incompatible-khwasan.rs @@ -1,4 +1,5 @@ -//@ compile-flags: -Z sanitizer=kernel-hwaddress -Z sanitizer=kernel-address --target aarch64-unknown-none +//@ compile-flags: -T sanitizer=kernel-hwaddress -T sanitizer=kernel-address --target aarch64-unknown-none +//@ compile-flags: -Z unstable-options //@ needs-llvm-components: aarch64 //@ ignore-backends: gcc @@ -6,4 +7,4 @@ #![no_core] #![no_main] -//~? ERROR `-Zsanitizer=kernel-address` is incompatible with `-Zsanitizer=kernel-hwaddress` +//~? ERROR `-Tsanitizer=kernel-address` is incompatible with `-Tsanitizer=kernel-hwaddress` diff --git a/tests/ui/sanitizer/incompatible-khwasan.stderr b/tests/ui/sanitizer/incompatible-khwasan.stderr index 35246fb266230..6b7b8176b1eb5 100644 --- a/tests/ui/sanitizer/incompatible-khwasan.stderr +++ b/tests/ui/sanitizer/incompatible-khwasan.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer=kernel-address` is incompatible with `-Zsanitizer=kernel-hwaddress` +error: `-Tsanitizer=kernel-address` is incompatible with `-Tsanitizer=kernel-hwaddress` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/incompatible.rs b/tests/ui/sanitizer/incompatible.rs index c706a5a2e4e7b..b4ce0b7a8756e 100644 --- a/tests/ui/sanitizer/incompatible.rs +++ b/tests/ui/sanitizer/incompatible.rs @@ -1,8 +1,8 @@ -//@ compile-flags: -Z sanitizer=address -Z sanitizer=memory --target x86_64-unknown-linux-gnu +//@ compile-flags: -Zsanitizer=address -Tsanitizer=memory --target x86_64-unknown-linux-gnu -Zunstable-options //@ needs-llvm-components: x86 #![feature(no_core)] #![no_core] #![no_main] -//~? ERROR `-Zsanitizer=address` is incompatible with `-Zsanitizer=memory` +//~? ERROR `-Zsanitizer=address` is incompatible with `-Tsanitizer=memory` diff --git a/tests/ui/sanitizer/incompatible.stderr b/tests/ui/sanitizer/incompatible.stderr index 4dff813ee1be6..7fded4645b1cc 100644 --- a/tests/ui/sanitizer/incompatible.stderr +++ b/tests/ui/sanitizer/incompatible.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer=address` is incompatible with `-Zsanitizer=memory` +error: `-Zsanitizer=address` is incompatible with `-Tsanitizer=memory` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/issue-114275-cfi-const-expr-in-arry-len.rs b/tests/ui/sanitizer/issue-114275-cfi-const-expr-in-arry-len.rs index f7af2842ad613..16cd4714153e0 100644 --- a/tests/ui/sanitizer/issue-114275-cfi-const-expr-in-arry-len.rs +++ b/tests/ui/sanitizer/issue-114275-cfi-const-expr-in-arry-len.rs @@ -2,7 +2,7 @@ // was expecting array type lengths to be evaluated, this was causing an ICE. // //@ build-pass -//@ compile-flags: -Ccodegen-units=1 -Clto -Zsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Ccodegen-units=1 -Clto -Tsanitizer=cfi -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options //@ needs-sanitizer-cfi #![crate_type = "lib"] diff --git a/tests/ui/sanitizer/kcfi-arity-requires-kcfi.rs b/tests/ui/sanitizer/kcfi-arity-requires-kcfi.rs index 12aabb3b86236..d617196aed563 100644 --- a/tests/ui/sanitizer/kcfi-arity-requires-kcfi.rs +++ b/tests/ui/sanitizer/kcfi-arity-requires-kcfi.rs @@ -3,7 +3,7 @@ //@ needs-sanitizer-kcfi //@ compile-flags: -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer-kcfi-arity -//~? ERROR `-Zsanitizer-kcfi-arity` requires `-Zsanitizer=kcfi` +//~? ERROR `-Zsanitizer-kcfi-arity` requires `-Tsanitizer=kcfi` #![feature(no_core)] #![no_core] #![no_main] diff --git a/tests/ui/sanitizer/kcfi-arity-requires-kcfi.stderr b/tests/ui/sanitizer/kcfi-arity-requires-kcfi.stderr index 4ed1b754fd431..75cdd9487006e 100644 --- a/tests/ui/sanitizer/kcfi-arity-requires-kcfi.stderr +++ b/tests/ui/sanitizer/kcfi-arity-requires-kcfi.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer-kcfi-arity` requires `-Zsanitizer=kcfi` +error: `-Zsanitizer-kcfi-arity` requires `-Tsanitizer=kcfi` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/kcfi-c-variadic.rs b/tests/ui/sanitizer/kcfi-c-variadic.rs index 2f88ccfb1269c..1541e584216f5 100644 --- a/tests/ui/sanitizer/kcfi-c-variadic.rs +++ b/tests/ui/sanitizer/kcfi-c-variadic.rs @@ -1,6 +1,7 @@ //@ needs-sanitizer-kcfi //@ no-prefer-dynamic -//@ compile-flags: -Zsanitizer=kcfi -Cpanic=abort -Cunsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Tsanitizer=kcfi -Cpanic=abort -Cunsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Zunstable-options //@ ignore-backends: gcc //@ run-pass diff --git a/tests/ui/sanitizer/kcfi-mangling.rs b/tests/ui/sanitizer/kcfi-mangling.rs index 371f34ba72af2..ff03254cd346d 100644 --- a/tests/ui/sanitizer/kcfi-mangling.rs +++ b/tests/ui/sanitizer/kcfi-mangling.rs @@ -2,7 +2,8 @@ //@ needs-sanitizer-kcfi //@ no-prefer-dynamic -//@ compile-flags: -C panic=abort -Zsanitizer=kcfi -C symbol-mangling-version=v0 -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -C panic=abort -Tsanitizer=kcfi -C symbol-mangling-version=v0 +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options //@ build-pass //@ ignore-backends: gcc diff --git a/tests/ui/sanitizer/kcfi/const-generics.rs b/tests/ui/sanitizer/kcfi/const-generics.rs index 86f487bb9ea1e..f770914bc6aac 100644 --- a/tests/ui/sanitizer/kcfi/const-generics.rs +++ b/tests/ui/sanitizer/kcfi/const-generics.rs @@ -4,7 +4,7 @@ //@ needs-sanitizer-kcfi //@ only-linux //@ ignore-backends: gcc -//@ compile-flags: -Ctarget-feature=-crt-static -Cpanic=abort -Cprefer-dynamic=off -Copt-level=0 -Zsanitizer=kcfi -Cunsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Ctarget-feature=-crt-static -Cpanic=abort -Cprefer-dynamic=off -Copt-level=0 -Tsanitizer=kcfi -Cunsafe-allow-abi-mismatch=sanitizer -Zunstable-options //@ run-pass #![feature(adt_const_params)] diff --git a/tests/ui/sanitizer/kcfi/fn-trait-objects.rs b/tests/ui/sanitizer/kcfi/fn-trait-objects.rs index 3f6b78545a0a1..7d6ea9148a30e 100644 --- a/tests/ui/sanitizer/kcfi/fn-trait-objects.rs +++ b/tests/ui/sanitizer/kcfi/fn-trait-objects.rs @@ -4,7 +4,7 @@ //@ needs-sanitizer-kcfi //@ only-linux //@ ignore-backends: gcc -//@ compile-flags: -Ctarget-feature=-crt-static -Zpanic_abort_tests -Cpanic=abort -Cprefer-dynamic=off -Copt-level=0 -Zsanitizer=kcfi -Cunsafe-allow-abi-mismatch=sanitizer --test +//@ compile-flags: -Ctarget-feature=-crt-static -Zpanic_abort_tests -Cpanic=abort -Cprefer-dynamic=off -Copt-level=0 -Tsanitizer=kcfi -Cunsafe-allow-abi-mismatch=sanitizer --test -Zunstable-options //@ run-pass #![feature(fn_traits)] diff --git a/tests/ui/sanitizer/unsupported-target-khwasan.rs b/tests/ui/sanitizer/unsupported-target-khwasan.rs index bef6d95e57b21..1a3c3167f1472 100644 --- a/tests/ui/sanitizer/unsupported-target-khwasan.rs +++ b/tests/ui/sanitizer/unsupported-target-khwasan.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Z sanitizer=kernel-hwaddress --target x86_64-unknown-none +//@ compile-flags: -Tsanitizer=kernel-hwaddress --target x86_64-unknown-none -Zunstable-options //@ needs-llvm-components: x86 //@ ignore-backends: gcc diff --git a/tests/ui/sanitizer/unsupported-target.rs b/tests/ui/sanitizer/unsupported-target.rs index 0776c769e0796..19a99c314387c 100644 --- a/tests/ui/sanitizer/unsupported-target.rs +++ b/tests/ui/sanitizer/unsupported-target.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Z sanitizer=leak --target i686-unknown-linux-gnu +//@ compile-flags: -Zsanitizer=leak --target i686-unknown-linux-gnu //@ needs-llvm-components: x86 //@ ignore-backends: gcc diff --git a/tests/ui/target_modifiers/auxiliary/kcfi-normalize-ints.rs b/tests/ui/target_modifiers/auxiliary/kcfi-normalize-ints.rs index f97005a14502d..9d213041e35bd 100644 --- a/tests/ui/target_modifiers/auxiliary/kcfi-normalize-ints.rs +++ b/tests/ui/target_modifiers/auxiliary/kcfi-normalize-ints.rs @@ -1,6 +1,6 @@ //@ no-prefer-dynamic //@ needs-sanitizer-kcfi -//@ compile-flags: -C panic=abort -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers +//@ compile-flags: -C panic=abort -Tsanitizer=kcfi -Tsanitizer-cfi-normalize-integers -Zunstable-options #![feature(no_core)] #![crate_type = "rlib"] diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.rs b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.rs index cb9f701349ae6..58249c5582c36 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.rs +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.rs @@ -1,17 +1,18 @@ -// For kCFI, the helper flag -Zsanitizer-cfi-normalize-integers should also be a target modifier. +// For kCFI, the helper flag -Tsanitizer-cfi-normalize-integers should also be a target modifier. //@ needs-sanitizer-kcfi //@ aux-build:kcfi-normalize-ints.rs //@ compile-flags: -Cpanic=abort //@ revisions: ok wrong_flag wrong_sanitizer -//@[ok] compile-flags: -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -//@[wrong_flag] compile-flags: -Zsanitizer=kcfi +//@[ok] compile-flags: -Tsanitizer=kcfi -Tsanitizer-cfi-normalize-integers -Zunstable-options +//@[wrong_flag] compile-flags: -Tsanitizer=kcfi -Zunstable-options //@[ok] check-pass #![feature(no_core)] -//[wrong_flag]~^ ERROR mixing `-Zsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` -//[wrong_sanitizer]~^^ ERROR mixing `-Zsanitizer` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` +//[wrong_flag]~^ ERROR mixing `-Tsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` +//[wrong_sanitizer]~^^ ERROR mixing `-Tsanitizer` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` +//[wrong_sanitizer]~| ERROR mixing `-Tsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` #![crate_type = "rlib"] #![no_core] diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr index c6abc4b574322..4e95d3431164c 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr @@ -1,12 +1,12 @@ -error: mixing `-Zsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` +error: mixing `-Tsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` --> $DIR/sanitizer-kcfi-normalize-ints.rs:12:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zsanitizer-cfi-normalize-integers` is unset in this crate which is incompatible with `-Zsanitizer-cfi-normalize-integers` being set in dependency `kcfi_normalize_ints` - = help: set `-Zsanitizer-cfi-normalize-integers` in this crate or unset `-Zsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` + = help: the `-Tsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers=true` in dependency `kcfi_normalize_ints` + = help: set `-Tsanitizer-cfi-normalize-integers=true` in this crate or unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer-cfi-normalize-integers` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr index 79e8ffbf04a5b..c768298c0294e 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr @@ -1,13 +1,24 @@ -error: mixing `-Zsanitizer` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` +error: mixing `-Tsanitizer` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` --> $DIR/sanitizer-kcfi-normalize-ints.rs:12:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Zsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Zsanitizer` is unset in this crate which is incompatible with `-Zsanitizer=kcfi` in dependency `kcfi_normalize_ints` - = help: set `-Zsanitizer=kcfi` in this crate or unset `-Zsanitizer` in `kcfi_normalize_ints` + = help: the `-Tsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Tsanitizer` in this crate is incompatible with `-Tsanitizer=kcfi` in dependency `kcfi_normalize_ints` + = help: set `-Tsanitizer=kcfi` in this crate or unset `-Tsanitizer` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer` to silence this error -error: aborting due to 1 previous error +error: mixing `-Tsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` + --> $DIR/sanitizer-kcfi-normalize-ints.rs:12:1 + | +LL | #![feature(no_core)] + | ^ + | + = help: the `-Tsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers=true` in dependency `kcfi_normalize_ints` + = help: set `-Tsanitizer-cfi-normalize-integers=true` in this crate or unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` + = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer-cfi-normalize-integers` to silence this error + +error: aborting due to 2 previous errors From 900485792b25d4ae3aafeba62a144d9dea2dc064 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 29 Jul 2026 12:46:18 +0000 Subject: [PATCH 13/29] sess: `-Tpointer-authentication` --- compiler/rustc_session/src/config.rs | 24 +++++++- compiler/rustc_session/src/diagnostics.rs | 2 +- compiler/rustc_session/src/options.rs | 55 ++++++++++++------- compiler/rustc_session/src/session.rs | 4 +- ...thentication_validation.all_unknown.stderr | 2 +- ...ter_authentication_validation.empty.stderr | 2 +- ...ter_authentication_validation.mixed.stderr | 2 +- ...nable_pointer_authentication_validation.rs | 19 ++++--- ...uthentication_validation.unprefixed.stderr | 2 +- .../invalid_target_pointer_authentication.rs | 4 +- ...valid_target_pointer_authentication.stderr | 2 +- ...on_not_supported_pointer_authentication.rs | 2 +- 12 files changed, 80 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 8a5bb54b75bfc..15faf31122e02 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1642,7 +1642,7 @@ impl fmt::Display for BranchProtection { } } -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq, Encodable, BlobDecodable)] pub enum PointerAuthOption { // See and Clang's command line reference: // @@ -1816,6 +1816,28 @@ fn parse_jobs_one( (n > 1).then_some(NonZero::new(usize::from(n)).unwrap()) } +impl fmt::Display for PointerAuthOption { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Aarch64JumpTableHardening => write!(f, "aarch64-jump-table-hardening"), + Self::AuthTraps => write!(f, "auth-traps"), + Self::Calls => write!(f, "calls"), + Self::ElfGot => write!(f, "elf-got"), + Self::FunctionPointerTypeDiscrimination => { + write!(f, "function-pointer-type-discrimination") + } + Self::IndirectGotos => write!(f, "indirect-gotos"), + Self::InitFini => write!(f, "init-fini"), + Self::InitFiniAddressDiscrimination => write!(f, "init-fini-address-discrimination"), + Self::Intrinsics => write!(f, "intrinsics"), + Self::ReturnAddresses => write!(f, "return-addresses"), + Self::TypeInfoVTPtrDisc => write!(f, "typeinfo-vt-ptr-discrimination"), + Self::VTPtrAddrDisc => write!(f, "vt-ptr-addr-discrimination"), + Self::VTPtrTypeDisc => write!(f, "vt-ptr-type-discrimination"), + } + } +} + pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { // First disallow some configuration given on the command line cfg::disallow_cfgs(sess, &user_cfg); diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index efe079fa95d52..8bf5a55479429 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -393,7 +393,7 @@ pub(crate) struct PointerAuthenticationTypeDiscriminationNotSupportedForTarget<' #[derive(Diagnostic)] #[diag( - "`-Z pointer-authentication` is not supported for target {$target_triple} and will be ignored" + "`-T pointer-authentication` is not supported for target {$target_triple} and will be ignored" )] pub(crate) struct PointerAuthenticationNotSupportedForTarget<'a> { pub(crate) target_triple: &'a TargetTuple, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3df8db5addefa..83584507b85ee 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -475,6 +475,23 @@ impl TargetModifierOptionValue for u32 { } } +impl TargetModifierOptionValue for Vec<(PointerAuthOption, bool)> { + fn to_string_for_diag(&self) -> String { + let mut parts = Vec::new(); + for (opt, pos) in self { + let polarity = if *pos { "+" } else { "-" }; + parts.push(format!("{polarity}{opt}")); + } + parts.join(",") + } +} + +impl TargetModifierOptionValue for String { + fn to_string_for_diag(&self) -> String { + self.to_string() + } +} + impl TargetModifierOptionValue for BranchProtection { fn to_string_for_diag(&self) -> String { self.to_string() @@ -2339,6 +2356,25 @@ target_modifier_options! { "make the x18 register reserved on AArch64 (default: no)"), indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE], "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), + pointer_authentication: Vec<(PointerAuthOption, bool)> = ( + Vec::new(), + parse_pointer_authentication_list_with_polarity, + [TRACKED_UNSTABLE], + "A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options: + `aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch + `auth-traps` - trap immediately on pointer authentication failure + `calls` - enable signing and authentication of all indirect calls + `elf-got` - enable authentication of pointers from GOT (ELF only) + `function-pointer-type-discrimination` - enable type discrimination on C function pointers + `indirect-gotos` - enable signing and authentication of indirect goto targets + `init-fini` - enable signing of function pointers in init/fini arrays + `init-fini-address-discrimination` - enable address discrimination in init/fini arrays + `intrinsics` - pointer authentication intrinsics + `return-addresses` - enable signing and authentication of return addresses + `typeinfo-vt-ptr-discrimination - incorporate type and address discrimination in authenticated vtable pointers for std::type_info + `vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers + `vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers + Example: `-Zpointer-authentication=+calls,-init-fini`."), reg_struct_return: bool = (false, parse_bool, [TRACKED_UNSTABLE], "On x86-32 targets, it overrides the default ABI to return small structs in registers."), regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE], @@ -2734,25 +2770,6 @@ options! { "whether to use the PLT when calling into shared libraries; only has effect for PIC code on systems with ELF binaries (default: PLT is disabled if full relro is enabled on x86_64)"), - pointer_authentication: Vec<(PointerAuthOption, bool)> = ( - Vec::new(), - parse_pointer_authentication_list_with_polarity, - [TRACKED], - "A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options: - `aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch - `auth-traps` - trap immediately on pointer authentication failure - `calls` - enable signing and authentication of all indirect calls - `elf-got` - enable authentication of pointers from GOT (ELF only) - `function-pointer-type-discrimination` - enable type discrimination on C function pointers - `indirect-gotos` - enable signing and authentication of indirect goto targets - `init-fini` - enable signing of function pointers in init/fini arrays - `init-fini-address-discrimination` - enable address discrimination in init/fini arrays - `intrinsics` - pointer authentication intrinsics - `return-addresses` - enable signing and authentication of return addresses - `typeinfo-vt-ptr-discrimination - incorporate type and address discrimination in authenticated vtable pointers for std::type_info - `vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers - `vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers - Example: `-Zpointer-authentication=+calls,-init-fini`."), polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED], "enable polonius-based borrow-checker (default: no)"), pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b9269d639f9bb..413bf9ff5879b 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1322,7 +1322,7 @@ pub fn build_session( let timings = TimingSectionHandler::new(sopts.json_timings); let pointer_auth_config: Option = - PointerAuthConfig::from_raw(&sopts.unstable_opts.pointer_authentication, &target); + PointerAuthConfig::from_raw(&sopts.target_opts.pointer_authentication, &target); let sess = Session { target, @@ -1403,7 +1403,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } if sess.target.cfg_abi != CfgAbi::Pauthtest - && !sess.opts.unstable_opts.pointer_authentication.is_empty() + && !sess.opts.target_opts.pointer_authentication.is_empty() { sess.dcx().emit_warn(diagnostics::PointerAuthenticationNotSupportedForTarget { target_triple: &sess.opts.target_triple, diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr index 47e61f2b8be73..793fedf401add 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr @@ -1,2 +1,2 @@ -error: incorrect value `+I,+do,-not,-exist` for unstable option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr index 9a4cd16c15a14..6e508b25967ae 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr @@ -1,2 +1,2 @@ -error: incorrect value `` for unstable option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr index ea8b9250f31b9..1e889bb97610b 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr @@ -1,2 +1,2 @@ -error: incorrect value `+elf-got,-imaginary` for unstable option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `+elf-got,-imaginary` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs index d7306508f39d4..700294765b875 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs @@ -1,24 +1,25 @@ //@ ignore-backends: gcc //@ revisions: empty unprefixed all_unknown all_known mixed +//@ compile-flags: -Zunstable-options //@[empty] needs-llvm-components: aarch64 -//@[empty] compile-flags: --target aarch64-unknown-linux-pauthtest -Zpointer-authentication= +//@[empty] compile-flags: --target aarch64-unknown-linux-pauthtest -Tpointer-authentication= //@[unprefixed] needs-llvm-components: aarch64 -//@[unprefixed] compile-flags: --target aarch64-unknown-linux-pauthtest -Zpointer-authentication=auth-traps +//@[unprefixed] compile-flags: --target aarch64-unknown-linux-pauthtest -Tpointer-authentication=auth-traps //@[all_unknown] needs-llvm-components: aarch64 -//@[all_unknown] compile-flags: --target aarch64-unknown-linux-pauthtest -Zpointer-authentication=+I,+do,-not,-exist +//@[all_unknown] compile-flags: --target aarch64-unknown-linux-pauthtest -Tpointer-authentication=+I,+do,-not,-exist //@[all_known] check-pass //@[all_known] needs-llvm-components: aarch64 -//@[all_known] compile-flags: --target aarch64-unknown-linux-pauthtest -Zpointer-authentication=+elf-got,-init-fini +//@[all_known] compile-flags: --target aarch64-unknown-linux-pauthtest -Tpointer-authentication=+elf-got,-init-fini //@[mixed] needs-llvm-components: aarch64 -//@[mixed] compile-flags: --target aarch64-unknown-linux-pauthtest -Zpointer-authentication=+elf-got,-imaginary +//@[mixed] compile-flags: --target aarch64-unknown-linux-pauthtest -Tpointer-authentication=+elf-got,-imaginary #![feature(no_core)] #![no_std] #![no_main] #![no_core] -//[empty]~? ERROR incorrect value `` for unstable option `pointer-authentication` -//[unprefixed]~? ERROR incorrect value `auth-traps` for unstable option `pointer-authentication` -//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for unstable option `pointer-authentication` -//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for unstable option `pointer-authentication` +//[empty]~? ERROR incorrect value `` for target option `pointer-authentication` +//[unprefixed]~? ERROR incorrect value `auth-traps` for target option `pointer-authentication` +//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication` +//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for target option `pointer-authentication` diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr index c6ff1e36350ee..00ad442d2823d 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr @@ -1,2 +1,2 @@ -error: incorrect value `auth-traps` for unstable option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `auth-traps` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs b/tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs index 2d8b3b7a1915d..696c18319ceef 100644 --- a/tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs +++ b/tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs @@ -2,10 +2,10 @@ //@ check-pass //@ needs-llvm-components: aarch64 -//@ compile-flags: -Zpointer-authentication=-elf-got --crate-type=lib --target aarch64-unknown-linux-gnu +//@ compile-flags: -Zunstable-options -Tpointer-authentication=-elf-got --crate-type=lib --target aarch64-unknown-linux-gnu #![feature(no_core)] #![no_std] #![no_main] #![no_core] -//~? WARN `-Z pointer-authentication` is not supported for target aarch64-unknown-linux-gnu and will be ignored +//~? WARN `-T pointer-authentication` is not supported for target aarch64-unknown-linux-gnu and will be ignored diff --git a/tests/ui/pointer_authentication/invalid_target_pointer_authentication.stderr b/tests/ui/pointer_authentication/invalid_target_pointer_authentication.stderr index 1b1a33fd16c2b..ffe7be3bf56c9 100644 --- a/tests/ui/pointer_authentication/invalid_target_pointer_authentication.stderr +++ b/tests/ui/pointer_authentication/invalid_target_pointer_authentication.stderr @@ -1,4 +1,4 @@ -warning: `-Z pointer-authentication` is not supported for target aarch64-unknown-linux-gnu and will be ignored +warning: `-T pointer-authentication` is not supported for target aarch64-unknown-linux-gnu and will be ignored warning: 1 warning emitted diff --git a/tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs b/tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs index 6838e749fd333..f30d14472d456 100644 --- a/tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs +++ b/tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs @@ -2,7 +2,7 @@ //@ check-fail //@ needs-llvm-components: aarch64 -//@ compile-flags: -Zpointer-authentication=+function-pointer-type-discrimination --crate-type=lib --target aarch64-unknown-linux-pauthtest +//@ compile-flags: -Zunstable-options -Tpointer-authentication=+function-pointer-type-discrimination --crate-type=lib --target aarch64-unknown-linux-pauthtest #![feature(no_core)] #![no_std] From d0041c0de62e844ebfeadfae6a4d07cbe7466597 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 29 Jul 2026 12:57:19 +0000 Subject: [PATCH 14/29] sess: `-Ttarget-cpu` --- compiler/rustc_codegen_cranelift/src/lib.rs | 4 +-- compiler/rustc_codegen_llvm/src/llvm_util.rs | 6 ++-- .../rustc_codegen_ssa/src/back/metadata.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 8 ++--- compiler/rustc_codegen_ssa/src/diagnostics.rs | 2 +- .../rustc_codegen_ssa/src/target_features.rs | 2 +- compiler/rustc_session/src/diagnostics.rs | 8 +++++ compiler/rustc_session/src/options.rs | 12 +++++--- compiler/rustc_session/src/session.rs | 30 ++++++++++++++++++- tests/assembly-llvm/asm/avr-modifiers.rs | 2 +- tests/assembly-llvm/asm/avr-types.rs | 2 +- tests/assembly-llvm/c-variadic/avr.rs | 2 +- tests/assembly-llvm/c-variadic/gpu.rs | 2 +- tests/assembly-llvm/targets/targets-amdgpu.rs | 2 +- tests/assembly-llvm/targets/targets-pe.rs | 2 +- tests/codegen-llvm/amdgpu-addrspacecast.rs | 2 +- tests/codegen-llvm/amdgpu-dispatch-ptr.rs | 2 +- tests/codegen-llvm/asm/avr-clobbers.rs | 2 +- tests/codegen-llvm/avr/avr-func-addrspace.rs | 2 +- tests/codegen-llvm/gpu-convergent.rs | 2 +- tests/codegen-llvm/gpu-kernel-abi.rs | 2 +- .../gpu-launch-sized-workgroup-memory.rs | 2 +- .../avr-custom-target-missing-cpu/rmake.rs | 2 +- tests/run-make/simd-ffi/rmake.rs | 2 +- .../target-cpu-as-target-modifier/rmake.rs | 21 +++++++------ tests/run-make/target-cpu-precedence/lib.rs | 4 +-- tests/run-make/target-cpu-precedence/rmake.rs | 4 +-- tests/run-make/target-specs/rmake.rs | 2 +- tests/ui/abi/avr-sram.rs | 6 ++-- tests/ui/abi/cannot-be-called.rs | 4 +-- tests/ui/abi/cannot-be-coroutine.rs | 4 +-- tests/ui/abi/cannot-return.rs | 2 +- tests/ui/abi/interrupt-invalid-signature.rs | 2 +- .../ui/abi/interrupt-returns-never-or-unit.rs | 2 +- tests/ui/cfg/cfg_target_object_format.rs | 2 +- .../feature-gate-abi-avr-interrupt.rs | 2 +- .../feature-gate-abi_gpu_kernel.rs | 2 +- ...ature-gate-c_variadic_experimental_arch.rs | 2 +- tests/ui/lint/lint-gpu-kernel.rs | 2 +- tests/ui/repr/16-bit-repr-c-enum.rs | 2 +- .../explicit-target-cpu.amdgcn_nocpu.stderr | 2 +- .../explicit-target-cpu.avr_nocpu.stderr | 2 +- tests/ui/target-cpu/explicit-target-cpu.rs | 10 +++---- tests/ui/target-cpu/unsupported-target-cpu.rs | 2 +- .../auxiliary/target_cpu_default_explicit.rs | 2 +- .../auxiliary/target_cpu_non_default.rs | 2 +- ...arget_cpu_default.explicit_mismatch.stderr | 8 ++--- ...arget_cpu_default.implicit_mismatch.stderr | 8 ++--- .../ui/target_modifiers/target_cpu_default.rs | 16 +++++----- 49 files changed, 131 insertions(+), 88 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index 8b0ca770ec067..8b092681e0c2c 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -206,7 +206,7 @@ impl CodegenBackend for CraneliftCodegenBackend { fn target_cpu(&self, sess: &Session) -> String { // FIXME handle `-Ctarget-cpu=native` - match sess.opts.cg.target_cpu { + match sess.target_cpu() { Some(ref name) => name, None => sess.target.cpu.as_ref(), } @@ -339,7 +339,7 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { let flags = settings::Flags::new(flags_builder); - let isa_builder = match sess.opts.cg.target_cpu.as_deref() { + let isa_builder = match sess.target_cpu().as_deref() { Some(NATIVE_CPU) => cranelift_native::builder_with_options(true).unwrap(), Some(value) => { let mut builder = diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index c95056fc41f3a..9cff8c8eefef5 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -624,7 +624,7 @@ fn handle_native(cpu_name: &str) -> &str { } pub(crate) fn target_cpu(sess: &Session) -> &str { - let cpu_name = sess.opts.cg.target_cpu.as_deref().unwrap_or_else(|| &sess.target.cpu); + let cpu_name = sess.target_cpu().unwrap_or_else(|| &sess.target.cpu); handle_native(cpu_name) } @@ -676,8 +676,8 @@ pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec let mut features = vec![]; // -Ctarget-cpu=native - match sess.opts.cg.target_cpu { - Some(ref s) if s == NATIVE_CPU => { + match sess.target_cpu() { + Some(s) if s == NATIVE_CPU => { // We have already figured out the actual CPU name with `LLVMRustGetHostCPUName` and set // that for LLVM, so the features implied by that CPU name will be available everywhere. // However, that is not sufficient: e.g. `skylake` alone is not sufficient to tell if diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index a43bf72b6a27d..6502052ec02d5 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -368,7 +368,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { Architecture::Avr => { // Resolve the ISA revision and set // the appropriate EF_AVR_ARCH flag. - if let Some(ref cpu) = sess.opts.cg.target_cpu { + if let Some(ref cpu) = sess.target_cpu() { ef_avr_arch(cpu) } else { sess.dcx().emit_fatal(diagnostics::CpuRequired) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 0468e3de18d8b..c25535d3d39a0 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -718,16 +718,16 @@ pub fn codegen_crate< backend: B, tcx: TyCtxt<'_>, ) -> OngoingCodegen { - if tcx.sess.target.need_explicit_cpu && tcx.sess.opts.cg.target_cpu.is_none() { + if tcx.sess.target.need_explicit_cpu && tcx.sess.target_cpu().is_none() { // The target has no default cpu, but none is set explicitly tcx.dcx().emit_fatal(diagnostics::CpuRequired); } - if let Some(target_cpu) = &tcx.sess.opts.cg.target_cpu - && tcx.sess.target.unsupported_cpus.contains(&target_cpu.into()) + if let Some(target_cpu) = &tcx.sess.target_cpu() + && tcx.sess.target.unsupported_cpus.contains(&(*target_cpu).into()) { // The target cpu is explicitly listed as an unsupported cpu - tcx.dcx().emit_fatal(diagnostics::CpuUnsupported { target_cpu: target_cpu.clone() }); + tcx.dcx().emit_fatal(diagnostics::CpuUnsupported { target_cpu: target_cpu.to_string() }); } let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx); diff --git a/compiler/rustc_codegen_ssa/src/diagnostics.rs b/compiler/rustc_codegen_ssa/src/diagnostics.rs index 2b77eb2cf24fb..6694ea34ee9f6 100644 --- a/compiler/rustc_codegen_ssa/src/diagnostics.rs +++ b/compiler/rustc_codegen_ssa/src/diagnostics.rs @@ -530,7 +530,7 @@ pub(crate) struct CheckInstalledVisualStudio; pub(crate) struct InsufficientVSCodeProduct; #[derive(Diagnostic)] -#[diag("target requires explicitly specifying a cpu with `-C target-cpu`")] +#[diag("target requires explicitly specifying a cpu with `-T target-cpu`")] pub(crate) struct CpuRequired; #[derive(Diagnostic)] diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index a2caca6df0dd1..6ce27b025402a 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -433,7 +433,7 @@ pub fn target_spec_to_backend_features<'a>( // sm_70, sm_72 and sm_75 defaults to PTX ISA versions with major version 6, while sm_80 default to 7.0 if sess.target.arch == Arch::Nvptx64 && matches!( - sess.opts.cg.target_cpu.as_deref(), + sess.target_cpu().as_deref(), None | Some("sm_70") | Some("sm_72") | Some("sm_75") ) { diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 8bf5a55479429..b61c5ed9ac302 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -774,3 +774,11 @@ pub(crate) struct IncompatibleFlagsUnsetLocally { pub flag_name: String, pub extern_value: String, } + +#[derive(Diagnostic)] +#[diag("`target-cpu` must be set with `-Ttarget-cpu` for this target")] +pub(crate) struct TargetCpuNeedsTargetModifierOpt; + +#[derive(Diagnostic)] +#[diag("`target-cpu` must be set with `-Ctarget-cpu` for this target")] +pub(crate) struct TargetCpuNeedsCodegenOpt; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 83584507b85ee..cc6ef8bcca688 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -71,14 +71,14 @@ pub mod mitigation_coverage; #[derive(Clone, Default)] pub struct OptionMetadata { /// Was this option set by the user? - is_set: bool, + pub(crate) is_set: bool, } #[derive(Clone, Default)] pub struct OptionsMetadata { - codegen: CodegenOptionsMetadata, - target: TargetOptionsMetadata, - unstable: UnstableOptionsMetadata, + pub(crate) codegen: CodegenOptionsMetadata, + pub(crate) target: TargetOptionsMetadata, + pub(crate) unstable: UnstableOptionsMetadata, } macro_rules! top_level_options { @@ -2331,6 +2331,7 @@ options! { symbol_mangling_version: Option = (None, parse_symbol_mangling_version, [TRACKED], "which mangling version to use for symbol names ('legacy', 'v0' (default), or 'hashed')"), + #[rustc_lint_opt_deny_field_access("use `Session::target_cpu` instead of this field")] target_cpu: Option = (None, parse_opt_string, [TRACKED], "select target processor (`rustc --print target-cpus` for details)"), target_feature: String = (String::new(), parse_target_feature, [TRACKED], @@ -2391,6 +2392,9 @@ target_modifier_options! { "use a sanitizer"), sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED_UNSTABLE], "enable normalizing integer types (default: no)"), + #[rustc_lint_opt_deny_field_access("use `Session::target_cpu` instead of this field")] + target_cpu: Option = (None, parse_opt_string, [TRACKED], + "select target processor (`rustc --print target-cpus` for details)"), // tidy-alphabetical-end // If you add a new option, please update: diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 413bf9ff5879b..e3c3f23ddee67 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -585,6 +585,20 @@ impl Session { &self.opts.unstable_opts.coverage_options } + // JUSTIFICATION: defn of wrapper around `target_cpu` + #[allow(rustc::bad_opt_access)] + pub fn target_cpu(&self) -> Option<&str> { + // `opts.target_opts.target_cpu` can have a value set so that default values of `target-cpu` + // match across crates, but the rest of the compiler expects this function to only return + // a value if it was explicitly set + let target_value = if self.opts.metadata.target.target_cpu.is_set { + self.opts.target_opts.target_cpu.as_deref() + } else { + None + }; + target_value.or(self.opts.cg.target_cpu.as_deref()) + } + pub fn is_sanitizer_cfi_enabled(&self) -> bool { self.sanitizers().contains(SanitizerSet::CFI) } @@ -1219,7 +1233,7 @@ fn default_emitter(sopts: &config::Options, source_map: Arc) -> Box, target: Target, @@ -1261,6 +1275,14 @@ pub fn build_session( dcx.handle().warn(warning) } + // If the target requires `target-opt` be a target modifier then it is desirable that the + // default for the option be compatible with an explicitly set `-Ttarget-cpu`, but because the + // `-Ttarget-cpu` default cannot be set in `options!` (it's target-specific, unsurprisingly), + // the default needs to be written here so it is in cross-crate metadata. + if target.requires_consistent_cpu && !sopts.metadata.target.target_cpu.is_set { + sopts.target_opts.target_cpu = Some(target.cpu.to_string()); + } + let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile { let directory = if let Some(directory) = d { directory } else { std::path::Path::new(".") }; @@ -1410,6 +1432,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) { }); } + if sess.target.requires_consistent_cpu && sess.opts.metadata.codegen.target_cpu.is_set { + sess.dcx().emit_err(diagnostics::TargetCpuNeedsTargetModifierOpt); + } else if !sess.target.requires_consistent_cpu && sess.opts.metadata.target.target_cpu.is_set { + sess.dcx().emit_err(diagnostics::TargetCpuNeedsCodegenOpt); + } + // Make sure that any given profiling data actually exists so LLVM can't // decide to silently skip PGO. if let Some(ref path) = sess.opts.cg.profile_use { diff --git a/tests/assembly-llvm/asm/avr-modifiers.rs b/tests/assembly-llvm/asm/avr-modifiers.rs index a65eeeced7077..717eee0bf06a8 100644 --- a/tests/assembly-llvm/asm/avr-modifiers.rs +++ b/tests/assembly-llvm/asm/avr-modifiers.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: --target avr-none -C target-cpu=atmega328p +//@ compile-flags: --target avr-none -T target-cpu=atmega328p //@ needs-llvm-components: avr #![feature(no_core, asm_experimental_arch)] diff --git a/tests/assembly-llvm/asm/avr-types.rs b/tests/assembly-llvm/asm/avr-types.rs index 29a937b58e9e0..5333cd5537744 100644 --- a/tests/assembly-llvm/asm/avr-types.rs +++ b/tests/assembly-llvm/asm/avr-types.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: --target avr-none -C target-cpu=atmega328p +//@ compile-flags: --target avr-none -T target-cpu=atmega328p //@ needs-llvm-components: avr #![feature(no_core, asm_experimental_arch)] diff --git a/tests/assembly-llvm/c-variadic/avr.rs b/tests/assembly-llvm/c-variadic/avr.rs index a795e57cb8287..223f580261871 100644 --- a/tests/assembly-llvm/c-variadic/avr.rs +++ b/tests/assembly-llvm/c-variadic/avr.rs @@ -2,7 +2,7 @@ //@ assembly-output: emit-asm // //@ revisions: AVR -//@ [AVR] compile-flags: -Copt-level=3 --target=avr-none -Ctarget-cpu=atmega328p +//@ [AVR] compile-flags: -Copt-level=3 --target=avr-none -Ttarget-cpu=atmega328p //@ [AVR] needs-llvm-components: avr #![feature(c_variadic_experimental_arch, no_core, lang_items, intrinsics, rustc_attrs)] #![no_core] diff --git a/tests/assembly-llvm/c-variadic/gpu.rs b/tests/assembly-llvm/c-variadic/gpu.rs index 0bc9c0f428705..dc2bd956746c5 100644 --- a/tests/assembly-llvm/c-variadic/gpu.rs +++ b/tests/assembly-llvm/c-variadic/gpu.rs @@ -3,7 +3,7 @@ //@ compile-flags: -Copt-level=3 // //@ revisions: AMDGPU NVPTX -//@ [AMDGPU] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ [AMDGPU] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ [AMDGPU] needs-llvm-components: amdgpu //@ [NVPTX] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda //@ [NVPTX] needs-llvm-components: nvptx diff --git a/tests/assembly-llvm/targets/targets-amdgpu.rs b/tests/assembly-llvm/targets/targets-amdgpu.rs index 69a90ff70bee9..a44d176dde76f 100644 --- a/tests/assembly-llvm/targets/targets-amdgpu.rs +++ b/tests/assembly-llvm/targets/targets-amdgpu.rs @@ -2,7 +2,7 @@ //@ assembly-output: emit-asm // ignore-tidy-linelength //@ revisions: amdgcn_amd_amdhsa -//@ [amdgcn_amd_amdhsa] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ [amdgcn_amd_amdhsa] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ [amdgcn_amd_amdhsa] needs-llvm-components: amdgpu // Sanity-check that each target can produce assembly code. diff --git a/tests/assembly-llvm/targets/targets-pe.rs b/tests/assembly-llvm/targets/targets-pe.rs index 2f4472ac74d9b..b963114eab39f 100644 --- a/tests/assembly-llvm/targets/targets-pe.rs +++ b/tests/assembly-llvm/targets/targets-pe.rs @@ -17,7 +17,7 @@ //@ [arm64ec_pc_windows_msvc] compile-flags: --target arm64ec-pc-windows-msvc //@ [arm64ec_pc_windows_msvc] needs-llvm-components: aarch64 //@ revisions: avr_none -//@ [avr_none] compile-flags: --target avr-none -C target-cpu=atmega328p +//@ [avr_none] compile-flags: --target avr-none -T target-cpu=atmega328p //@ [avr_none] needs-llvm-components: avr //@ revisions: bpfeb_unknown_none //@ [bpfeb_unknown_none] compile-flags: --target bpfeb-unknown-none diff --git a/tests/codegen-llvm/amdgpu-addrspacecast.rs b/tests/codegen-llvm/amdgpu-addrspacecast.rs index 144565f7e28ca..29db57865bc20 100644 --- a/tests/codegen-llvm/amdgpu-addrspacecast.rs +++ b/tests/codegen-llvm/amdgpu-addrspacecast.rs @@ -1,6 +1,6 @@ // Check that pointers are casted to addrspace(0) before they are used -//@ compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 -O +//@ compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 -O //@ needs-llvm-components: amdgpu //@ add-minicore //@ revisions: LLVM21 LLVM22 diff --git a/tests/codegen-llvm/amdgpu-dispatch-ptr.rs b/tests/codegen-llvm/amdgpu-dispatch-ptr.rs index 00bde96c3d596..743673b1ef6c5 100644 --- a/tests/codegen-llvm/amdgpu-dispatch-ptr.rs +++ b/tests/codegen-llvm/amdgpu-dispatch-ptr.rs @@ -1,6 +1,6 @@ // Tests the amdgpu_dispatch_ptr intrinsic. -//@ compile-flags: --crate-type=rlib --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ compile-flags: --crate-type=rlib --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ needs-llvm-components: amdgpu //@ add-minicore #![feature(intrinsics, no_core, rustc_attrs)] diff --git a/tests/codegen-llvm/asm/avr-clobbers.rs b/tests/codegen-llvm/asm/avr-clobbers.rs index 472ee328465b6..626483ecf2530 100644 --- a/tests/codegen-llvm/asm/avr-clobbers.rs +++ b/tests/codegen-llvm/asm/avr-clobbers.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ assembly-output: emit-asm -//@ compile-flags: --target avr-none -C target-cpu=atmega328p +//@ compile-flags: --target avr-none -T target-cpu=atmega328p //@ needs-llvm-components: avr #![crate_type = "rlib"] diff --git a/tests/codegen-llvm/avr/avr-func-addrspace.rs b/tests/codegen-llvm/avr/avr-func-addrspace.rs index 8812992050325..e6e76ccadec86 100644 --- a/tests/codegen-llvm/avr/avr-func-addrspace.rs +++ b/tests/codegen-llvm/avr/avr-func-addrspace.rs @@ -1,5 +1,5 @@ //@ add-minicore -//@ compile-flags: -Copt-level=3 --target=avr-none -C target-cpu=atmega328p --crate-type=rlib -C panic=abort +//@ compile-flags: -Copt-level=3 --target=avr-none -T target-cpu=atmega328p --crate-type=rlib -C panic=abort //@ needs-llvm-components: avr // This test validates that function pointers can be stored in global variables diff --git a/tests/codegen-llvm/gpu-convergent.rs b/tests/codegen-llvm/gpu-convergent.rs index 376d65a3d4a25..069d3cc55167b 100644 --- a/tests/codegen-llvm/gpu-convergent.rs +++ b/tests/codegen-llvm/gpu-convergent.rs @@ -3,7 +3,7 @@ //@ add-minicore //@ revisions: amdgpu nvptx -//@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ [amdgpu] needs-llvm-components: amdgpu //@ [nvptx] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda //@ [nvptx] needs-llvm-components: nvptx diff --git a/tests/codegen-llvm/gpu-kernel-abi.rs b/tests/codegen-llvm/gpu-kernel-abi.rs index 828b10c37880d..dbf6ba301b000 100644 --- a/tests/codegen-llvm/gpu-kernel-abi.rs +++ b/tests/codegen-llvm/gpu-kernel-abi.rs @@ -2,7 +2,7 @@ //@ add-minicore //@ revisions: amdgpu nvptx -//@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ [amdgpu] needs-llvm-components: amdgpu //@ [nvptx] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda //@ [nvptx] needs-llvm-components: nvptx diff --git a/tests/codegen-llvm/gpu-launch-sized-workgroup-memory.rs b/tests/codegen-llvm/gpu-launch-sized-workgroup-memory.rs index 4764160fd0b59..e06c92492ee2b 100644 --- a/tests/codegen-llvm/gpu-launch-sized-workgroup-memory.rs +++ b/tests/codegen-llvm/gpu-launch-sized-workgroup-memory.rs @@ -4,7 +4,7 @@ //@ revisions: amdgpu nvptx-pre-llvm-23 nvptx-post-llvm-23 //@ compile-flags: --crate-type=rlib -Copt-level=1 // -//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@ [amdgpu] needs-llvm-components: amdgpu //@ [nvptx-pre-llvm-23] compile-flags: --target nvptx64-nvidia-cuda diff --git a/tests/run-make/avr-custom-target-missing-cpu/rmake.rs b/tests/run-make/avr-custom-target-missing-cpu/rmake.rs index d076eb3d378b2..615932e69885b 100644 --- a/tests/run-make/avr-custom-target-missing-cpu/rmake.rs +++ b/tests/run-make/avr-custom-target-missing-cpu/rmake.rs @@ -12,5 +12,5 @@ fn main() { .target("avr-custom-missing-cpu.json") .crate_type("lib") .run_fail() - .assert_stderr_contains("target requires explicitly specifying a cpu with `-C target-cpu`"); + .assert_stderr_contains("target requires explicitly specifying a cpu with `-T target-cpu`"); } diff --git a/tests/run-make/simd-ffi/rmake.rs b/tests/run-make/simd-ffi/rmake.rs index 054ea402a698d..60d19ce16dfbf 100644 --- a/tests/run-make/simd-ffi/rmake.rs +++ b/tests/run-make/simd-ffi/rmake.rs @@ -64,7 +64,7 @@ fn main() { } else if target.starts_with("mips") { "+msa,+fp64" } else if target.starts_with("amdgcn") { - cmd.arg("-Ctarget-cpu=gfx900"); + cmd.arg("-Ttarget-cpu=gfx900"); "" } else { panic!("missing target_feature case for {target}"); diff --git a/tests/run-make/target-cpu-as-target-modifier/rmake.rs b/tests/run-make/target-cpu-as-target-modifier/rmake.rs index a3be062dd8090..2afe059debc3e 100644 --- a/tests/run-make/target-cpu-as-target-modifier/rmake.rs +++ b/tests/run-make/target-cpu-as-target-modifier/rmake.rs @@ -75,37 +75,40 @@ fn verify_cross_crate_compatibility() { let targets: Vec<&str> = target_list.lines().collect(); for target in targets.iter() { - let compiler = |cpu: &str, input: &str| { + let compiler = |cpu: &str, input: &str, prefix: &str| { let mut cmd = rustc(); cmd.target(target) - .target_cpu(cpu) + .arg(format!("-{prefix}target-cpu={cpu}")) .input(input) .panic("abort") .args(["--emit=metadata", "-Zcodegen-backend=dummy"]); cmd }; let (first_cpu, second_cpu) = ("A", "B"); + let prefix = if EXPECTED.contains(target) { "T" } else { "C" }; // Build dependency.rs using the first target-cpu - compiler(first_cpu, "dependency.rs").run(); + compiler(first_cpu, "dependency.rs", prefix).run(); if EXPECTED.contains(target) { - // Testing targets where `-Ctarget-cpu` acts as a target modifier: + // Testing targets where `-Ttarget-cpu` acts as a target modifier: // Building with the same target cpu must succeed. - compiler(first_cpu, "main.rs").run(); + compiler(first_cpu, "main.rs", prefix).run(); // Building with a different target cpu must succeed if // rustc is invoked with `-Cunsafe-allow-abi-mismatch=target-cpu` - compiler(second_cpu, "main.rs").arg("-Cunsafe-allow-abi-mismatch=target-cpu").run(); + compiler(second_cpu, "main.rs", prefix) + .arg("-Cunsafe-allow-abi-mismatch=target-cpu") + .run(); // Building with a different target cpu must fail if // rustc is _not_ invoked with `-Cunsafe-allow-abi-mismatch=target-cpu` - compiler(second_cpu, "main.rs").run_fail().assert_stderr_contains( - "error: mixing `-Ctarget-cpu` will cause \ + compiler(second_cpu, "main.rs", prefix).run_fail().assert_stderr_contains( + "error: mixing `-Ttarget-cpu` will cause \ an ABI mismatch in crate `main`", ); } else { // Testing targets where `-Ctarget-cpu` does not act as a target modifier: // Building with a different target cpu must succeed. - compiler(second_cpu, "main.rs").run(); + compiler(second_cpu, "main.rs", prefix).run(); } } } diff --git a/tests/run-make/target-cpu-precedence/lib.rs b/tests/run-make/target-cpu-precedence/lib.rs index 3f92f54eb357e..d343e7762d53c 100644 --- a/tests/run-make/target-cpu-precedence/lib.rs +++ b/tests/run-make/target-cpu-precedence/lib.rs @@ -24,7 +24,7 @@ pub trait MetaSized: PointeeSized {} pub trait Sized: MetaSized {} // Capture the effective CPU from LLVM IR. This also verifies that the second -// `-Ctarget-cpu` argument took precedence. +// `-Ttarget-cpu` argument took precedence. // CHECK-LABEL: target triple = "nvptx64-nvidia-cuda" // CHECK-LABEL: define {{.*}} @foo() {{.*}} #0 // CHECK-LABEL: attributes #0 = {{.*}} "target-cpu"="sm_80" {{.*}} @@ -34,4 +34,4 @@ pub fn foo() { } // The value reconstructed from crate metadata must be identical. // CHECK-LABEL: =Target modifiers= -// CHECK-LABEL: -Ctarget-cpu=sm_80 [Some("sm_80")] +// CHECK-LABEL: -Ttarget-cpu=sm_80 ["sm_80"] diff --git a/tests/run-make/target-cpu-precedence/rmake.rs b/tests/run-make/target-cpu-precedence/rmake.rs index 13dfcd72e3891..57fb2a742e496 100644 --- a/tests/run-make/target-cpu-precedence/rmake.rs +++ b/tests/run-make/target-cpu-precedence/rmake.rs @@ -15,8 +15,8 @@ fn main() { .input("lib.rs") .crate_name("target_cpu_precedence") .target(TARGET) - .target_cpu(FIRST_CPU) - .target_cpu(LAST_CPU) + .arg(format!("-Ttarget-cpu={FIRST_CPU}")) + .arg(format!("-Ttarget-cpu={LAST_CPU}")) .emit("llvm-ir=output.ll,metadata=output.rmeta") .run(); diff --git a/tests/run-make/target-specs/rmake.rs b/tests/run-make/target-specs/rmake.rs index 6c88f3164e9e4..aeb5d2a1d3524 100644 --- a/tests/run-make/target-specs/rmake.rs +++ b/tests/run-make/target-specs/rmake.rs @@ -93,7 +93,7 @@ fn main() { .input("foo.rs") .target("require-explicit-cpu") .crate_type("lib") - .arg("-Ctarget-cpu=generic") + .arg("-Ttarget-cpu=generic") .run(); rustc().arg("-Zunstable-options").target("require-explicit-cpu").print("target-cpus").run(); } diff --git a/tests/ui/abi/avr-sram.rs b/tests/ui/abi/avr-sram.rs index 0266f7d6b22ca..d5ebec2cd46e6 100644 --- a/tests/ui/abi/avr-sram.rs +++ b/tests/ui/abi/avr-sram.rs @@ -1,10 +1,10 @@ //@ revisions: has_sram no_sram disable_sram //@ build-pass -//@[has_sram] compile-flags: --target avr-none -C target-cpu=atmega328p +//@[has_sram] compile-flags: --target avr-none -T target-cpu=atmega328p //@[has_sram] needs-llvm-components: avr -//@[no_sram] compile-flags: --target avr-none -C target-cpu=attiny11 +//@[no_sram] compile-flags: --target avr-none -T target-cpu=attiny11 //@[no_sram] needs-llvm-components: avr -//@[disable_sram] compile-flags: --target avr-none -C target-cpu=atmega328p -C target-feature=-sram +//@[disable_sram] compile-flags: --target avr-none -T target-cpu=atmega328p -C target-feature=-sram //@[disable_sram] needs-llvm-components: avr //@ ignore-backends: gcc //[no_sram,disable_sram]~? WARN target feature `sram` must be enabled diff --git a/tests/ui/abi/cannot-be-called.rs b/tests/ui/abi/cannot-be-called.rs index eef2f8c671efa..e92898de3bf77 100644 --- a/tests/ui/abi/cannot-be-called.rs +++ b/tests/ui/abi/cannot-be-called.rs @@ -17,11 +17,11 @@ So we test that they error in essentially all of the same places. //@ [riscv64] needs-llvm-components: riscv //@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib //@ [avr] needs-llvm-components: avr -//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ [avr] compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ [msp430] needs-llvm-components: msp430 //@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib //@ [amdgpu] needs-llvm-components: amdgpu -//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib +//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx //@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib //@ ignore-backends: gcc diff --git a/tests/ui/abi/cannot-be-coroutine.rs b/tests/ui/abi/cannot-be-coroutine.rs index 239f5aa5c31fe..89a86baad6bc5 100644 --- a/tests/ui/abi/cannot-be-coroutine.rs +++ b/tests/ui/abi/cannot-be-coroutine.rs @@ -13,11 +13,11 @@ //@ [riscv64] needs-llvm-components: riscv //@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib //@ [avr] needs-llvm-components: avr -//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ [avr] compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ [msp430] needs-llvm-components: msp430 //@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib //@ [amdgpu] needs-llvm-components: amdgpu -//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib +//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx //@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib //@ ignore-backends: gcc diff --git a/tests/ui/abi/cannot-return.rs b/tests/ui/abi/cannot-return.rs index 9a5db30431b9f..ba737c7dc328b 100644 --- a/tests/ui/abi/cannot-return.rs +++ b/tests/ui/abi/cannot-return.rs @@ -4,7 +4,7 @@ //@ revisions: amdgpu nvptx // //@ [amdgpu] needs-llvm-components: amdgpu -//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 --crate-type=rlib +//@ [amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 --crate-type=rlib //@ [nvptx] needs-llvm-components: nvptx //@ [nvptx] compile-flags: --target nvptx64-nvidia-cuda --crate-type=rlib #![no_core] diff --git a/tests/ui/abi/interrupt-invalid-signature.rs b/tests/ui/abi/interrupt-invalid-signature.rs index 083d93fef0774..5d8c7901b4a5c 100644 --- a/tests/ui/abi/interrupt-invalid-signature.rs +++ b/tests/ui/abi/interrupt-invalid-signature.rs @@ -19,7 +19,7 @@ This test uses `cfg` because it is not testing whether these ABIs work on the pl //@ [riscv64] needs-llvm-components: riscv //@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib //@ [avr] needs-llvm-components: avr -//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ [avr] compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ [msp430] needs-llvm-components: msp430 //@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib //@ ignore-backends: gcc diff --git a/tests/ui/abi/interrupt-returns-never-or-unit.rs b/tests/ui/abi/interrupt-returns-never-or-unit.rs index 75786730a2ca4..c552008200b35 100644 --- a/tests/ui/abi/interrupt-returns-never-or-unit.rs +++ b/tests/ui/abi/interrupt-returns-never-or-unit.rs @@ -18,7 +18,7 @@ This test uses `cfg` because it is not testing whether these ABIs work on the pl //@ [riscv64] needs-llvm-components: riscv //@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib //@ [avr] needs-llvm-components: avr -//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ [avr] compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ [msp430] needs-llvm-components: msp430 //@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib //@ ignore-backends: gcc diff --git a/tests/ui/cfg/cfg_target_object_format.rs b/tests/ui/cfg/cfg_target_object_format.rs index cea2027b35c0b..87a036a9d87e8 100644 --- a/tests/ui/cfg/cfg_target_object_format.rs +++ b/tests/ui/cfg/cfg_target_object_format.rs @@ -49,7 +49,7 @@ //@[bpfel] needs-llvm-components: bpf // //@ revisions: avr -//@[avr] compile-flags: --target avr-none -Ctarget-cpu=atmega328 +//@[avr] compile-flags: --target avr-none -Ttarget-cpu=atmega328 //@[avr] needs-llvm-components: avr // //@ revisions: msp430 diff --git a/tests/ui/feature-gates/feature-gate-abi-avr-interrupt.rs b/tests/ui/feature-gates/feature-gate-abi-avr-interrupt.rs index 164bc1b5c29db..e491ecb66dad7 100644 --- a/tests/ui/feature-gates/feature-gate-abi-avr-interrupt.rs +++ b/tests/ui/feature-gates/feature-gate-abi-avr-interrupt.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ needs-llvm-components: avr -//@ compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ ignore-backends: gcc #![no_core] #![feature(no_core, lang_items)] diff --git a/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs b/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs index d442c9317f64e..54d225657b4da 100644 --- a/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs +++ b/tests/ui/feature-gates/feature-gate-abi_gpu_kernel.rs @@ -1,7 +1,7 @@ //@ revisions: HOST AMDGPU NVPTX //@ add-minicore //@ compile-flags: --crate-type=rlib -//@[AMDGPU] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx1100 +//@[AMDGPU] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx1100 //@[AMDGPU] needs-llvm-components: amdgpu //@[NVPTX] compile-flags: --target nvptx64-nvidia-cuda //@[NVPTX] needs-llvm-components: nvptx diff --git a/tests/ui/feature-gates/feature-gate-c_variadic_experimental_arch.rs b/tests/ui/feature-gates/feature-gate-c_variadic_experimental_arch.rs index 49c0bdf3a724b..d1820f98a3dd9 100644 --- a/tests/ui/feature-gates/feature-gate-c_variadic_experimental_arch.rs +++ b/tests/ui/feature-gates/feature-gate-c_variadic_experimental_arch.rs @@ -9,7 +9,7 @@ //@[sparc] compile-flags: --target sparc-unknown-none-elf //@[sparc] needs-llvm-components: sparc // -//@[avr] compile-flags: --target avr-none -Ctarget-cpu=atmega328p +//@[avr] compile-flags: --target avr-none -Ttarget-cpu=atmega328p //@[avr] needs-llvm-components: avr // //@[m68k] compile-flags: --target m68k-unknown-none-elf -Ctarget-cpu=M68020 diff --git a/tests/ui/lint/lint-gpu-kernel.rs b/tests/ui/lint/lint-gpu-kernel.rs index 9b3ed0d14d8ad..7ac97745b2774 100644 --- a/tests/ui/lint/lint-gpu-kernel.rs +++ b/tests/ui/lint/lint-gpu-kernel.rs @@ -6,7 +6,7 @@ //@ revisions: amdgpu nvptx //@ add-minicore //@ edition: 2024 -//@[amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 +//@[amdgpu] compile-flags: --target amdgcn-amd-amdhsa -Ttarget-cpu=gfx900 //@[amdgpu] needs-llvm-components: amdgpu //@[nvptx] compile-flags: --target nvptx64-nvidia-cuda //@[nvptx] needs-llvm-components: nvptx diff --git a/tests/ui/repr/16-bit-repr-c-enum.rs b/tests/ui/repr/16-bit-repr-c-enum.rs index f981ea23ee24e..0d9a40aa7d2e2 100644 --- a/tests/ui/repr/16-bit-repr-c-enum.rs +++ b/tests/ui/repr/16-bit-repr-c-enum.rs @@ -3,7 +3,7 @@ //@ revisions: avr msp430 // //@ [avr] needs-llvm-components: avr -//@ [avr] compile-flags: --target=avr-none -C target-cpu=atmega328p --crate-type=rlib +//@ [avr] compile-flags: --target=avr-none -T target-cpu=atmega328p --crate-type=rlib //@ [msp430] needs-llvm-components: msp430 //@ [msp430] compile-flags: --target=msp430-none-elf --crate-type=rlib //@ ignore-backends: gcc diff --git a/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr b/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr index 7480a8ed38f15..c2b1a09cf7f98 100644 --- a/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr +++ b/tests/ui/target-cpu/explicit-target-cpu.amdgcn_nocpu.stderr @@ -1,4 +1,4 @@ -error: target requires explicitly specifying a cpu with `-C target-cpu` +error: target requires explicitly specifying a cpu with `-T target-cpu` error: aborting due to 1 previous error diff --git a/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr b/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr index 7480a8ed38f15..c2b1a09cf7f98 100644 --- a/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr +++ b/tests/ui/target-cpu/explicit-target-cpu.avr_nocpu.stderr @@ -1,4 +1,4 @@ -error: target requires explicitly specifying a cpu with `-C target-cpu` +error: target requires explicitly specifying a cpu with `-T target-cpu` error: aborting due to 1 previous error diff --git a/tests/ui/target-cpu/explicit-target-cpu.rs b/tests/ui/target-cpu/explicit-target-cpu.rs index 29f8e9de1f6ea..65cdb5ea49249 100644 --- a/tests/ui/target-cpu/explicit-target-cpu.rs +++ b/tests/ui/target-cpu/explicit-target-cpu.rs @@ -1,4 +1,4 @@ -//! Check that certain target *requires* the user to specify a target CPU via `-C target-cpu`. +//! Check that certain target *requires* the user to specify a target CPU via `-T target-cpu`. //@ revisions: amdgcn_nocpu amdgcn_cpu @@ -8,7 +8,7 @@ //@[amdgcn_cpu] compile-flags: --target=amdgcn-amd-amdhsa //@[amdgcn_cpu] needs-llvm-components: amdgpu -//@[amdgcn_cpu] compile-flags: -Ctarget-cpu=gfx900 +//@[amdgcn_cpu] compile-flags: -Ttarget-cpu=gfx900 //@[amdgcn_cpu] build-pass //@ revisions: avr_nocpu avr_cpu @@ -19,16 +19,16 @@ //@[avr_cpu] compile-flags: --target=avr-none //@[avr_cpu] needs-llvm-components: avr -//@[avr_cpu] compile-flags: -Ctarget-cpu=atmega328p +//@[avr_cpu] compile-flags: -Ttarget-cpu=atmega328p //@[avr_cpu] build-pass //@ ignore-backends: gcc #![crate_type = "rlib"] // We don't want to link in any other crate as this would make it necessary to specify -// a `-Ctarget-cpu` for them resulting in a *target-modifier* disagreement error instead of the +// a `-Ttarget-cpu` for them resulting in a *target-modifier* disagreement error instead of the // error mentioned below. #![feature(no_core)] #![no_core] -//[amdgcn_nocpu,avr_nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu` +//[amdgcn_nocpu,avr_nocpu]~? ERROR target requires explicitly specifying a cpu with `-T target-cpu` diff --git a/tests/ui/target-cpu/unsupported-target-cpu.rs b/tests/ui/target-cpu/unsupported-target-cpu.rs index dafbfbc015ec1..4e92cce5ee07a 100644 --- a/tests/ui/target-cpu/unsupported-target-cpu.rs +++ b/tests/ui/target-cpu/unsupported-target-cpu.rs @@ -2,7 +2,7 @@ //@ revisions: nvptx-sm60 -//@[nvptx-sm60] compile-flags: --target=nvptx64-nvidia-cuda --crate-type=rlib -Ctarget-cpu=sm_60 +//@[nvptx-sm60] compile-flags: --target=nvptx64-nvidia-cuda --crate-type=rlib -Ttarget-cpu=sm_60 //@[nvptx-sm60] needs-llvm-components: nvptx //@[nvptx-sm60] build-fail //@ ignore-backends: gcc diff --git a/tests/ui/target_modifiers/auxiliary/target_cpu_default_explicit.rs b/tests/ui/target_modifiers/auxiliary/target_cpu_default_explicit.rs index 3c56f64dfdb3a..1b29a1f3d01c2 100644 --- a/tests/ui/target_modifiers/auxiliary/target_cpu_default_explicit.rs +++ b/tests/ui/target_modifiers/auxiliary/target_cpu_default_explicit.rs @@ -1,5 +1,5 @@ //@ no-prefer-dynamic -//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_70 +//@ compile-flags: --target nvptx64-nvidia-cuda -Ttarget-cpu=sm_70 //@ needs-llvm-components: nvptx //@ ignore-backends: gcc diff --git a/tests/ui/target_modifiers/auxiliary/target_cpu_non_default.rs b/tests/ui/target_modifiers/auxiliary/target_cpu_non_default.rs index a4fa7e2a33af6..11912587520fe 100644 --- a/tests/ui/target_modifiers/auxiliary/target_cpu_non_default.rs +++ b/tests/ui/target_modifiers/auxiliary/target_cpu_non_default.rs @@ -1,5 +1,5 @@ //@ no-prefer-dynamic -//@ compile-flags: --target nvptx64-nvidia-cuda -Ctarget-cpu=sm_80 +//@ compile-flags: --target nvptx64-nvidia-cuda -Ttarget-cpu=sm_80 //@ needs-llvm-components: nvptx //@ ignore-backends: gcc diff --git a/tests/ui/target_modifiers/target_cpu_default.explicit_mismatch.stderr b/tests/ui/target_modifiers/target_cpu_default.explicit_mismatch.stderr index 775569818175b..dcbf72801149a 100644 --- a/tests/ui/target_modifiers/target_cpu_default.explicit_mismatch.stderr +++ b/tests/ui/target_modifiers/target_cpu_default.explicit_mismatch.stderr @@ -1,12 +1,12 @@ -error: mixing `-Ctarget-cpu` will cause an ABI mismatch in crate `target_cpu_default` +error: mixing `-Ttarget-cpu` will cause an ABI mismatch in crate `target_cpu_default` --> $DIR/target_cpu_default.rs:25:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Ctarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Ctarget-cpu=sm_70` in this crate is incompatible with `-Ctarget-cpu=sm_80` in dependency `target_cpu_non_default` - = help: set `-Ctarget-cpu=sm_80` in this crate or `-Ctarget-cpu=sm_70` in `target_cpu_non_default` + = help: the `-Ttarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: `-Ttarget-cpu=sm_70` in this crate is incompatible with `-Ttarget-cpu=sm_80` in dependency `target_cpu_non_default` + = help: set `-Ttarget-cpu=sm_80` in this crate or `-Ttarget-cpu=sm_70` in `target_cpu_non_default` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=target-cpu` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr b/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr index ecfef76992d37..bf4ecb952a229 100644 --- a/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr +++ b/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr @@ -1,12 +1,12 @@ -error: mixing `-Ctarget-cpu` will cause an ABI mismatch in crate `target_cpu_default` +error: mixing `-Ttarget-cpu` will cause an ABI mismatch in crate `target_cpu_default` --> $DIR/target_cpu_default.rs:25:1 | LL | #![feature(no_core)] | ^ | - = help: the `-Ctarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Ctarget-cpu` is unset in this crate which is incompatible with `-Ctarget-cpu=sm_80` in dependency `target_cpu_non_default` - = help: set `-Ctarget-cpu=sm_80` in this crate or unset `-Ctarget-cpu` in `target_cpu_non_default` + = help: the `-Ttarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Ttarget-cpu` in this crate is incompatible with `-Ttarget-cpu=sm_80` in dependency `target_cpu_non_default` + = help: set `-Ttarget-cpu=sm_80` in this crate or unset `-Ttarget-cpu` in `target_cpu_non_default` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=target-cpu` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/target_cpu_default.rs b/tests/ui/target_modifiers/target_cpu_default.rs index b4f3a5afda2e6..7f5309c4e0c9d 100644 --- a/tests/ui/target_modifiers/target_cpu_default.rs +++ b/tests/ui/target_modifiers/target_cpu_default.rs @@ -1,9 +1,9 @@ -// Check that an implicit default `-Ctarget-cpu` and an explicit default -// `-Ctarget-cpu` compare equal. +// Check that an implicit default `-Ttarget-cpu` and an explicit default +// `-Ttarget-cpu` compare equal. // -// NVPTX requires consistent `-Ctarget-cpu` values across crates, but it does +// NVPTX requires consistent `-Ttarget-cpu` values across crates, but it does // not require the CPU to be specified explicitly. Therefore, compiling one crate -// without `-Ctarget-cpu` and another crate with the target's default CPU +// without `-Ttarget-cpu` and another crate with the target's default CPU // explicitly specified must be accepted. // // The mismatch revisions additionally check that an implicit or explicit default @@ -18,13 +18,13 @@ //@ revisions: implicit_default explicit_default implicit_mismatch explicit_mismatch //@[implicit_default] check-pass -//@[explicit_default] compile-flags: -Ctarget-cpu=sm_70 +//@[explicit_default] compile-flags: -Ttarget-cpu=sm_70 //@[explicit_default] check-pass -//@[explicit_mismatch] compile-flags: -Ctarget-cpu=sm_70 +//@[explicit_mismatch] compile-flags: -Ttarget-cpu=sm_70 #![feature(no_core)] -//[implicit_mismatch]~^ ERROR mixing `-Ctarget-cpu` will cause an ABI mismatch -//[explicit_mismatch]~^^ ERROR mixing `-Ctarget-cpu` will cause an ABI mismatch +//[implicit_mismatch]~^ ERROR mixing `-Ttarget-cpu` will cause an ABI mismatch +//[explicit_mismatch]~^^ ERROR mixing `-Ttarget-cpu` will cause an ABI mismatch #![crate_type = "rlib"] #![no_core] From e01c5aba32ef7481c2cdd801352c09e1b022d2a3 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 12 Aug 2026 13:21:16 +0000 Subject: [PATCH 15/29] sess: `-Tllvm-target-feature` --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 4 ++-- compiler/rustc_session/src/options.rs | 8 ++++---- tests/ui/target-feature/llvm-target-feature.rs | 2 +- tests/ui/target-feature/missing-plusminus-llvm.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 9cff8c8eefef5..c47af74871a9e 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -746,9 +746,9 @@ pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec // asm logic uses that to check which registers may be used). llvm_features_by_flags(sess, &mut features); - // `-Zllvm-target-features`, all the way at the end to overwrite everything. + // `-Tllvm-target-features`, all the way at the end to overwrite everything. // Should be picked up by `cfg` (e.g. if someone enables AVX this way). - for feature in sess.opts.unstable_opts.llvm_target_feature.split(',') { + for feature in sess.opts.target_opts.llvm_target_feature.split(',') { if feature.is_empty() { continue; } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index cc6ef8bcca688..584881218286b 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2357,6 +2357,10 @@ target_modifier_options! { "make the x18 register reserved on AArch64 (default: no)"), indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE], "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), + llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED_UNSTABLE], + "enable/disable LLVM-level target features. \ + This feature is unsafe and can cause ABI issues and compiler crashes, \ + because LLVM does not support all target feature combinations."), pointer_authentication: Vec<(PointerAuthOption, bool)> = ( Vec::new(), parse_pointer_authentication_list_with_polarity, @@ -2662,10 +2666,6 @@ options! { "a list of module flags to pass to LLVM (space separated)"), llvm_plugins: Vec = (Vec::new(), parse_list, [TRACKED], "a list LLVM plugins to enable (space separated)"), - llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED], - "enable/disable LLVM-level target features. \ - This feature is unsafe and can cause ABI issues and compiler crashes, \ - because LLVM does not support all target feature combinations."), llvm_time_trace: bool = (false, parse_bool, [UNTRACKED], "generate JSON tracing data file from LLVM data (default: no)"), llvm_writable: bool = (false, parse_bool, [TRACKED], diff --git a/tests/ui/target-feature/llvm-target-feature.rs b/tests/ui/target-feature/llvm-target-feature.rs index 6b94574d3a8e4..941dcddd18f1d 100644 --- a/tests/ui/target-feature/llvm-target-feature.rs +++ b/tests/ui/target-feature/llvm-target-feature.rs @@ -4,7 +4,7 @@ //@ compile-flags: --crate-type=lib //@ compile-flags: --target=x86_64-unknown-linux-gnu -//@ compile-flags: -Zllvm-target-feature=+avx2 +//@ compile-flags: -Tllvm-target-feature=+avx2 -Zunstable-options //@ needs-llvm-components: x86 //@ build-pass diff --git a/tests/ui/target-feature/missing-plusminus-llvm.rs b/tests/ui/target-feature/missing-plusminus-llvm.rs index fe3c2cfcf2bd3..dab6267fe4cc6 100644 --- a/tests/ui/target-feature/missing-plusminus-llvm.rs +++ b/tests/ui/target-feature/missing-plusminus-llvm.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Zllvm-target-feature=banana --crate-type=rlib +//@ compile-flags: -Tllvm-target-feature=banana --crate-type=rlib -Zunstable-options //@ build-pass //@ ignore-backends: gcc From 98dfa1e52472bd218f6fd7869bd081a3fcfb9b5e Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 16/29] sess: add `is_target_modifier` option to setters This additional argument will be used in a future commit to allow some flags to accept arguments on when used as target modifiers (once flags can be both `-T` and `-C`). --- compiler/rustc_session/src/options.rs | 305 +++++++++++++++++++------- 1 file changed, 228 insertions(+), 77 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 584881218286b..8efa3ed14618c 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -290,6 +290,7 @@ macro_rules! setter_for { collected: &mut super::CollectedOptions, v: Option<&str>, index: usize, + _: bool, ) -> bool { collected.mitigations.handle_allowdeny_mitigation_option(v, index, true) } @@ -300,6 +301,7 @@ macro_rules! setter_for { collected: &mut super::CollectedOptions, v: Option<&str>, index: usize, + _: bool, ) -> bool { collected.mitigations.handle_allowdeny_mitigation_option(v, index, false) } @@ -310,9 +312,10 @@ macro_rules! setter_for { collected: &mut super::CollectedOptions, v: Option<&str>, _index: usize, + is_target_modifier: bool, ) -> bool { collected.metadata.$group_name.$opt.is_set = v.is_some(); - super::parse::$parse(&mut redirect_field!(cg.$opt), v) + super::parse::$parse(&mut redirect_field!(cg.$opt), v, is_target_modifier) } }; } @@ -656,7 +659,13 @@ macro_rules! redirect_field { }; } -type OptionSetter = fn(&mut O, &mut CollectedOptions, v: Option<&str>, pos: usize) -> bool; +type OptionSetter = fn( + &mut O, + &mut CollectedOptions, + v: Option<&str>, + pos: usize, + is_target_modifier: bool, +) -> bool; type OptionDescrs = &'static [OptionDesc]; /// Indicates whether a removed option should warn or error. @@ -717,7 +726,7 @@ fn build_options( } } } - if !setter(&mut op, collected_options, value, index) { + if !setter(&mut op, collected_options, value, index, false) { match value { None => early_dcx.early_fatal( format!( @@ -884,7 +893,7 @@ pub mod parse { /// Ignore the value. Used for removed options where we don't actually want to store /// anything in the session. - pub(crate) fn parse_ignore(_slot: &mut (), _v: Option<&str>) -> bool { + pub(crate) fn parse_ignore(_slot: &mut (), _v: Option<&str>, _: bool) -> bool { true } @@ -893,7 +902,7 @@ pub mod parse { /// /// This style of option is deprecated, and is mainly used by old options /// beginning with `no-`. - pub(crate) fn parse_no_value(slot: &mut bool, v: Option<&str>) -> bool { + pub(crate) fn parse_no_value(slot: &mut bool, v: Option<&str>, _: bool) -> bool { match v { None => { *slot = true; @@ -905,7 +914,7 @@ pub mod parse { } /// Use this for any boolean option that has a static default. - pub(crate) fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool { + pub(crate) fn parse_bool(slot: &mut bool, v: Option<&str>, _: bool) -> bool { match v { Some("y") | Some("yes") | Some("on") | Some("true") | None => { *slot = true; @@ -922,7 +931,7 @@ pub mod parse { /// Use this for any boolean option that lacks a static default. (The /// actions taken when such an option is not specified will depend on /// other factors, such as other options, or target options.) - pub(crate) fn parse_opt_bool(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_opt_bool(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v { Some("y") | Some("yes") | Some("on") | Some("true") | None => { *slot = Some(true); @@ -937,7 +946,7 @@ pub mod parse { } /// Parses whether polonius is enabled, and if so, which version. - pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>) -> bool { + pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>, _: bool) -> bool { match v { Some("legacy") | None => { *slot = Polonius::Legacy; @@ -955,7 +964,11 @@ pub mod parse { } } - pub(crate) fn parse_annotate_moves(slot: &mut AnnotateMoves, v: Option<&str>) -> bool { + pub(crate) fn parse_annotate_moves( + slot: &mut AnnotateMoves, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { let mut bslot = false; let mut nslot = 0u64; @@ -963,7 +976,7 @@ pub mod parse { // No value provided: -Z annotate-moves (enable with default limit) None => AnnotateMoves::Enabled(None), // Explicit boolean value provided: -Z annotate-moves=yes/no - s @ Some(_) if parse_bool(&mut bslot, s) => { + s @ Some(_) if parse_bool(&mut bslot, s, is_target_modifier) => { if bslot { AnnotateMoves::Enabled(None) } else { @@ -971,7 +984,9 @@ pub mod parse { } } // With numeric limit provided: -Z annotate-moves=1234 - s @ Some(_) if parse_number(&mut nslot, s) => AnnotateMoves::Enabled(Some(nslot)), + s @ Some(_) if parse_number(&mut nslot, s, is_target_modifier) => { + AnnotateMoves::Enabled(Some(nslot)) + } _ => return false, }; @@ -979,7 +994,7 @@ pub mod parse { } /// Use this for any string option that has a static default. - pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool { + pub(crate) fn parse_string(slot: &mut String, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { *slot = s.to_string(); @@ -990,7 +1005,7 @@ pub mod parse { } /// Use this for any string option that lacks a static default. - pub(crate) fn parse_opt_string(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_opt_string(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { *slot = Some(s.to_string()); @@ -1000,7 +1015,7 @@ pub mod parse { } } - pub(crate) fn parse_opt_pathbuf(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_opt_pathbuf(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { *slot = Some(PathBuf::from(s)); @@ -1010,7 +1025,7 @@ pub mod parse { } } - pub(crate) fn parse_string_push(slot: &mut Vec, v: Option<&str>) -> bool { + pub(crate) fn parse_string_push(slot: &mut Vec, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { slot.push(s.to_string()); @@ -1020,7 +1035,7 @@ pub mod parse { } } - pub(crate) fn parse_list(slot: &mut Vec, v: Option<&str>) -> bool { + pub(crate) fn parse_list(slot: &mut Vec, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { slot.extend(s.split_whitespace().map(|s| s.to_string())); @@ -1033,6 +1048,7 @@ pub mod parse { pub(crate) fn parse_list_with_polarity( slot: &mut Vec<(String, bool)>, v: Option<&str>, + _: bool, ) -> bool { match v { Some(s) => { @@ -1049,6 +1065,7 @@ pub mod parse { pub(crate) fn parse_pointer_authentication_list_with_polarity( slot: &mut Vec<(PointerAuthOption, bool)>, v: Option<&str>, + _: bool, ) -> bool { let Some(s) = v else { return false; @@ -1077,7 +1094,7 @@ pub mod parse { true } - pub(crate) fn parse_fmt_debug(opt: &mut FmtDebug, v: Option<&str>) -> bool { + pub(crate) fn parse_fmt_debug(opt: &mut FmtDebug, v: Option<&str>, _: bool) -> bool { *opt = match v { Some("full") => FmtDebug::Full, Some("shallow") => FmtDebug::Shallow, @@ -1087,7 +1104,7 @@ pub mod parse { true } - pub(crate) fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>) -> bool { + pub(crate) fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>, _: bool) -> bool { if let Some(v) = v { ld.line = false; ld.file = false; @@ -1109,7 +1126,7 @@ pub mod parse { } } - pub(crate) fn parse_comma_list(slot: &mut Vec, v: Option<&str>) -> bool { + pub(crate) fn parse_comma_list(slot: &mut Vec, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect(); @@ -1121,7 +1138,11 @@ pub mod parse { } } - pub(crate) fn parse_opt_comma_list(slot: &mut Option>, v: Option<&str>) -> bool { + pub(crate) fn parse_opt_comma_list( + slot: &mut Option>, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some(s) => { let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect(); @@ -1134,7 +1155,7 @@ pub mod parse { } /// Use this for any numeric option that has a static default. - pub(crate) fn parse_number(slot: &mut T, v: Option<&str>) -> bool { + pub(crate) fn parse_number(slot: &mut T, v: Option<&str>, _: bool) -> bool { match v.and_then(|s| s.parse().ok()) { Some(i) => { *slot = i; @@ -1148,6 +1169,7 @@ pub mod parse { pub(crate) fn parse_opt_number( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v { Some(s) => { @@ -1158,11 +1180,17 @@ pub mod parse { } } - pub(crate) fn parse_frame_pointer(slot: &mut FramePointer, v: Option<&str>) -> bool { + pub(crate) fn parse_frame_pointer( + slot: &mut FramePointer, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { let mut yes = false; match v { - _ if parse_bool(&mut yes, v) && yes => slot.ratchet(FramePointer::Always), - _ if parse_bool(&mut yes, v) => slot.ratchet(FramePointer::MayOmit), + _ if parse_bool(&mut yes, v, is_target_modifier) && yes => { + slot.ratchet(FramePointer::Always) + } + _ if parse_bool(&mut yes, v, is_target_modifier) => slot.ratchet(FramePointer::MayOmit), Some("always") => slot.ratchet(FramePointer::Always), Some("non-leaf") => slot.ratchet(FramePointer::NonLeaf), _ => return false, @@ -1170,7 +1198,11 @@ pub mod parse { true } - pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool { + pub(crate) fn parse_passes( + slot: &mut Passes, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { match v { Some("all") => { *slot = Passes::All; @@ -1178,7 +1210,7 @@ pub mod parse { } v => { let mut passes = vec![]; - if parse_list(&mut passes, v) { + if parse_list(&mut passes, v, is_target_modifier) { slot.extend(passes); true } else { @@ -1191,6 +1223,7 @@ pub mod parse { pub(crate) fn parse_opt_panic_strategy( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v { Some("unwind") => *slot = Some(PanicStrategy::Unwind), @@ -1201,7 +1234,7 @@ pub mod parse { true } - pub(crate) fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool { + pub(crate) fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>, _: bool) -> bool { match v { Some("unwind") => *slot = PanicStrategy::Unwind, Some("abort") => *slot = PanicStrategy::Abort, @@ -1211,7 +1244,7 @@ pub mod parse { true } - pub(crate) fn parse_on_broken_pipe(slot: &mut OnBrokenPipe, v: Option<&str>) -> bool { + pub(crate) fn parse_on_broken_pipe(slot: &mut OnBrokenPipe, v: Option<&str>, _: bool) -> bool { match v { // OnBrokenPipe::Default can't be explicitly specified Some("kill") => *slot = OnBrokenPipe::Kill, @@ -1225,21 +1258,22 @@ pub mod parse { pub(crate) fn parse_patchable_function_entry( slot: &mut PatchableFunctionEntry, v: Option<&str>, + is_target_modifier: bool, ) -> bool { let mut total_nops = 0; let mut prefix_nops = 0; let mut section = None; - if !parse_number(&mut total_nops, v) { + if !parse_number(&mut total_nops, v, is_target_modifier) { let parts: Vec<_> = v.unwrap_or("").split(',').collect(); if parts.len() < 2 || parts.len() > 3 { return false; } - if !parse_number(&mut total_nops, Some(parts[0])) { + if !parse_number(&mut total_nops, Some(parts[0]), is_target_modifier) { return false; } - if !parse_number(&mut prefix_nops, Some(parts[1])) { + if !parse_number(&mut prefix_nops, Some(parts[1]), is_target_modifier) { return false; } section = parts.get(2).map(|x| x.to_string()); @@ -1252,7 +1286,11 @@ pub mod parse { false } - pub(crate) fn parse_relro_level(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_relro_level( + slot: &mut Option, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some(s) => match s.parse::() { Ok(level) => *slot = Some(level), @@ -1324,19 +1362,31 @@ pub mod parse { } } - pub(crate) fn parse_sanitizers_all(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + pub(crate) fn parse_sanitizers_all(slot: &mut SanitizerSet, v: Option<&str>, _: bool) -> bool { parse_sanitizers(slot, v, SanitizerFilter::All) } - pub(crate) fn parse_sanitizers_target(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + pub(crate) fn parse_sanitizers_target( + slot: &mut SanitizerSet, + v: Option<&str>, + _: bool, + ) -> bool { parse_sanitizers(slot, v, SanitizerFilter::TargetModifiers) } - pub(crate) fn parse_sanitizers_other(slot: &mut SanitizerSet, v: Option<&str>) -> bool { + pub(crate) fn parse_sanitizers_other( + slot: &mut SanitizerSet, + v: Option<&str>, + _: bool, + ) -> bool { parse_sanitizers(slot, v, SanitizerFilter::NonTargetModifiers) } - pub(crate) fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool { + pub(crate) fn parse_sanitizer_memory_track_origins( + slot: &mut usize, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some("2") | None => { *slot = 2; @@ -1354,7 +1404,7 @@ pub mod parse { } } - pub(crate) fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool { + pub(crate) fn parse_strip(slot: &mut Strip, v: Option<&str>, _: bool) -> bool { match v { Some("none") => *slot = Strip::None, Some("debuginfo") => *slot = Strip::Debuginfo, @@ -1364,10 +1414,14 @@ pub mod parse { true } - pub(crate) fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool { + pub(crate) fn parse_cfguard( + slot: &mut CFGuard, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled }; return true; } @@ -1382,10 +1436,14 @@ pub mod parse { true } - pub(crate) fn parse_cfprotection(slot: &mut CFProtection, v: Option<&str>) -> bool { + pub(crate) fn parse_cfprotection( + slot: &mut CFProtection, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { CFProtection::Full } else { CFProtection::None }; return true; } @@ -1401,7 +1459,7 @@ pub mod parse { true } - pub(crate) fn parse_debuginfo(slot: &mut DebugInfo, v: Option<&str>) -> bool { + pub(crate) fn parse_debuginfo(slot: &mut DebugInfo, v: Option<&str>, _: bool) -> bool { match v { Some("0") | Some("none") => *slot = DebugInfo::None, Some("line-directives-only") => *slot = DebugInfo::LineDirectivesOnly, @@ -1416,6 +1474,7 @@ pub mod parse { pub(crate) fn parse_debuginfo_compression( slot: &mut DebugInfoCompression, v: Option<&str>, + _: bool, ) -> bool { match v { Some("none") => *slot = DebugInfoCompression::None, @@ -1426,7 +1485,11 @@ pub mod parse { true } - pub(crate) fn parse_mir_strip_debuginfo(slot: &mut MirStripDebugInfo, v: Option<&str>) -> bool { + pub(crate) fn parse_mir_strip_debuginfo( + slot: &mut MirStripDebugInfo, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some("none") => *slot = MirStripDebugInfo::None, Some("locals-in-tiny-functions") => *slot = MirStripDebugInfo::LocalsInTinyFunctions, @@ -1436,7 +1499,11 @@ pub mod parse { true } - pub(crate) fn parse_linker_flavor(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_linker_flavor( + slot: &mut Option, + v: Option<&str>, + _: bool, + ) -> bool { match v.and_then(|v| LinkerFlavorCli::from_str(v).ok()) { Some(lf) => *slot = Some(lf), _ => return false, @@ -1447,6 +1514,7 @@ pub mod parse { pub(crate) fn parse_opt_symbol_visibility( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { if let Some(v) = v { if let Ok(vis) = SymbolVisibility::from_str(v) { @@ -1458,7 +1526,7 @@ pub mod parse { true } - pub(crate) fn parse_unpretty(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_unpretty(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v { None => false, Some(s) if s.split('=').count() <= 2 => { @@ -1469,7 +1537,11 @@ pub mod parse { } } - pub(crate) fn parse_time_passes_format(slot: &mut TimePassesFormat, v: Option<&str>) -> bool { + pub(crate) fn parse_time_passes_format( + slot: &mut TimePassesFormat, + v: Option<&str>, + _: bool, + ) -> bool { match v { None => true, Some("json") => { @@ -1484,7 +1556,11 @@ pub mod parse { } } - pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&str>) -> bool { + pub(crate) fn parse_dump_mono_stats( + slot: &mut DumpMonoStatsFormat, + v: Option<&str>, + _: bool, + ) -> bool { match v { None => true, Some("json") => { @@ -1499,7 +1575,7 @@ pub mod parse { } } - pub(crate) fn parse_offload(slot: &mut Vec, v: Option<&str>) -> bool { + pub(crate) fn parse_offload(slot: &mut Vec, v: Option<&str>, _: bool) -> bool { let Some(v) = v else { *slot = vec![]; return true; @@ -1546,7 +1622,7 @@ pub mod parse { true } - pub(crate) fn parse_autodiff(slot: &mut Vec, v: Option<&str>) -> bool { + pub(crate) fn parse_autodiff(slot: &mut Vec, v: Option<&str>, _: bool) -> bool { let Some(v) = v else { *slot = vec![]; return true; @@ -1595,10 +1671,11 @@ pub mod parse { pub(crate) fn parse_instrument_coverage( slot: &mut InstrumentCoverage, v: Option<&str>, + is_target_modifier: bool, ) -> bool { if v.is_some() { let mut bool_arg = false; - if parse_bool(&mut bool_arg, v) { + if parse_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg { InstrumentCoverage::Yes } else { InstrumentCoverage::No }; return true; } @@ -1622,6 +1699,7 @@ pub mod parse { pub(crate) fn parse_codegen_retag_options( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { let mut no_precise_im = false; let mut no_precise_pin = false; @@ -1642,7 +1720,11 @@ pub mod parse { true } - pub(crate) fn parse_coverage_options(slot: &mut CoverageOptions, v: Option<&str>) -> bool { + pub(crate) fn parse_coverage_options( + slot: &mut CoverageOptions, + v: Option<&str>, + _: bool, + ) -> bool { let Some(v) = v else { return true }; for option in v.split(',') { @@ -1657,10 +1739,14 @@ pub mod parse { true } - pub(crate) fn parse_instrument_mcount(slot: &mut InstrumentMcount, v: Option<&str>) -> bool { + pub(crate) fn parse_instrument_mcount( + slot: &mut InstrumentMcount, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { let mut use_mcount = false; let mut opts = InstrumentMcountOpts::default(); - if parse_bool(&mut use_mcount, v) { + if parse_bool(&mut use_mcount, v, is_target_modifier) { *slot = if use_mcount { InstrumentMcount::Mcount(opts) } else { @@ -1691,10 +1777,11 @@ pub mod parse { pub(crate) fn parse_instrument_xray( slot: &mut Option, v: Option<&str>, + is_target_modifier: bool, ) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { Some(InstrumentXRay::default()) } else { None }; return true; } @@ -1753,6 +1840,7 @@ pub mod parse { pub(crate) fn parse_treat_err_as_bug( slot: &mut Option>, v: Option<&str>, + _: bool, ) -> bool { match v { Some(s) => match s.parse() { @@ -1772,7 +1860,11 @@ pub mod parse { } } - pub(crate) fn parse_next_solver_config(slot: &mut NextSolverConfig, v: Option<&str>) -> bool { + pub(crate) fn parse_next_solver_config( + slot: &mut NextSolverConfig, + v: Option<&str>, + _: bool, + ) -> bool { if let Some(config) = v { *slot = match config { "no" => NextSolverConfig { coherence: false, globally: false }, @@ -1787,10 +1879,10 @@ pub mod parse { true } - pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool { + pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>, is_target_modifier: bool) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No }; return true; } @@ -1805,10 +1897,14 @@ pub mod parse { true } - pub(crate) fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool { + pub(crate) fn parse_linker_plugin_lto( + slot: &mut LinkerPluginLto, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { LinkerPluginLto::LinkerPluginAuto } else { @@ -1828,6 +1924,7 @@ pub mod parse { pub(crate) fn parse_switch_with_opt_path( slot: &mut SwitchWithOptPath, v: Option<&str>, + _: bool, ) -> bool { *slot = match v { None => SwitchWithOptPath::Enabled(None), @@ -1839,6 +1936,7 @@ pub mod parse { pub(crate) fn parse_merge_functions( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v.and_then(|s| MergeFunctions::from_str(s).ok()) { Some(mergefunc) => *slot = Some(mergefunc), @@ -1847,7 +1945,11 @@ pub mod parse { true } - pub(crate) fn parse_relocation_model(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_relocation_model( + slot: &mut Option, + v: Option<&str>, + _: bool, + ) -> bool { match v.and_then(|s| RelocModel::from_str(s).ok()) { Some(relocation_model) => *slot = Some(relocation_model), None if v == Some("default") => *slot = None, @@ -1856,7 +1958,7 @@ pub mod parse { true } - pub(crate) fn parse_code_model(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_code_model(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v.and_then(|s| CodeModel::from_str(s).ok()) { Some(code_model) => *slot = Some(code_model), _ => return false, @@ -1864,7 +1966,7 @@ pub mod parse { true } - pub(crate) fn parse_tls_model(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_tls_model(slot: &mut Option, v: Option<&str>, _: bool) -> bool { match v.and_then(|s| TlsModel::from_str(s).ok()) { Some(tls_model) => *slot = Some(tls_model), _ => return false, @@ -1872,7 +1974,7 @@ pub mod parse { true } - pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool { + pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>, _: bool) -> bool { *slot = match v { Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes, Some("off" | "no" | "n") => TerminalUrl::No, @@ -1885,6 +1987,7 @@ pub mod parse { pub(crate) fn parse_symbol_mangling_version( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { *slot = match v { Some("legacy") => Some(SymbolManglingVersion::Legacy), @@ -1898,6 +2001,7 @@ pub mod parse { pub(crate) fn parse_src_file_hash( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) { Some(hash_kind) => *slot = Some(hash_kind), @@ -1909,6 +2013,7 @@ pub mod parse { pub(crate) fn parse_cargo_src_file_hash( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) { Some(hash_kind) => { @@ -1919,7 +2024,7 @@ pub mod parse { true } - pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool { + pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>, _: bool) -> bool { match v { Some(s) => { if !slot.is_empty() { @@ -1932,7 +2037,11 @@ pub mod parse { } } - pub(crate) fn parse_link_self_contained(slot: &mut LinkSelfContained, v: Option<&str>) -> bool { + pub(crate) fn parse_link_self_contained( + slot: &mut LinkSelfContained, + v: Option<&str>, + _: bool, + ) -> bool { // Whenever `-C link-self-contained` is passed without a value, it's an opt-in // just like `parse_opt_bool`, the historical value of this flag. // @@ -1961,7 +2070,11 @@ pub mod parse { } /// Parse a comma-separated list of enabled and disabled linker features. - pub(crate) fn parse_linker_features(slot: &mut LinkerFeaturesCli, v: Option<&str>) -> bool { + pub(crate) fn parse_linker_features( + slot: &mut LinkerFeaturesCli, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some(s) => { for feature in s.split(',') { @@ -1976,7 +2089,11 @@ pub mod parse { } } - pub(crate) fn parse_wasi_exec_model(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_wasi_exec_model( + slot: &mut Option, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some("command") => *slot = Some(WasiExecModel::Command), Some("reactor") => *slot = Some(WasiExecModel::Reactor), @@ -1988,6 +2105,7 @@ pub mod parse { pub(crate) fn parse_split_debuginfo( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) { Some(e) => *slot = Some(e), @@ -1996,7 +2114,11 @@ pub mod parse { true } - pub(crate) fn parse_split_dwarf_kind(slot: &mut SplitDwarfKind, v: Option<&str>) -> bool { + pub(crate) fn parse_split_dwarf_kind( + slot: &mut SplitDwarfKind, + v: Option<&str>, + _: bool, + ) -> bool { match v.and_then(|s| SplitDwarfKind::from_str(s).ok()) { Some(e) => *slot = e, _ => return false, @@ -2004,7 +2126,11 @@ pub mod parse { true } - pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool { + pub(crate) fn parse_stack_protector( + slot: &mut StackProtector, + v: Option<&str>, + _: bool, + ) -> bool { match v.and_then(|s| StackProtector::from_str(s).ok()) { Some(ssp) => *slot = ssp, _ => return false, @@ -2015,6 +2141,7 @@ pub mod parse { pub(crate) fn parse_branch_protection( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { match v { Some(s) => { @@ -2054,10 +2181,11 @@ pub mod parse { pub(crate) fn parse_collapse_macro_debuginfo( slot: &mut CollapseMacroDebuginfo, v: Option<&str>, + is_target_modifier: bool, ) -> bool { if v.is_some() { let mut bool_arg = None; - if parse_opt_bool(&mut bool_arg, v) { + if parse_opt_bool(&mut bool_arg, v, is_target_modifier) { *slot = if bool_arg.unwrap() { CollapseMacroDebuginfo::Yes } else { @@ -2077,6 +2205,7 @@ pub mod parse { pub(crate) fn parse_proc_macro_execution_strategy( slot: &mut ProcMacroExecutionStrategy, v: Option<&str>, + _: bool, ) -> bool { *slot = match v { Some("same-thread") => ProcMacroExecutionStrategy::SameThread, @@ -2086,7 +2215,11 @@ pub mod parse { true } - pub(crate) fn parse_inlining_threshold(slot: &mut InliningThreshold, v: Option<&str>) -> bool { + pub(crate) fn parse_inlining_threshold( + slot: &mut InliningThreshold, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some("always" | "yes") => { *slot = InliningThreshold::Always; @@ -2109,6 +2242,7 @@ pub mod parse { pub(crate) fn parse_llvm_module_flag( slot: &mut Vec<(String, u32, String)>, v: Option<&str>, + _: bool, ) -> bool { let elements = v.unwrap_or_default().split(':').collect::>(); let [key, md_type, value, behavior] = elements.as_slice() else { @@ -2133,7 +2267,11 @@ pub mod parse { true } - pub(crate) fn parse_function_return(slot: &mut FunctionReturn, v: Option<&str>) -> bool { + pub(crate) fn parse_function_return( + slot: &mut FunctionReturn, + v: Option<&str>, + _: bool, + ) -> bool { match v { Some("keep") => *slot = FunctionReturn::Keep, Some("thunk-extern") => *slot = FunctionReturn::ThunkExtern, @@ -2142,11 +2280,15 @@ pub mod parse { true } - pub(crate) fn parse_wasm_c_abi(_slot: &mut (), v: Option<&str>) -> bool { + pub(crate) fn parse_wasm_c_abi(_slot: &mut (), v: Option<&str>, _: bool) -> bool { v == Some("spec") } - pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool { + pub(crate) fn parse_mir_include_spans( + slot: &mut MirIncludeSpans, + v: Option<&str>, + _: bool, + ) -> bool { *slot = match v { Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On, Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off, @@ -2157,9 +2299,13 @@ pub mod parse { true } - pub(crate) fn parse_align(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_align( + slot: &mut Option, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { let mut bytes = 0u64; - if !parse_number(&mut bytes, v) { + if !parse_number(&mut bytes, v, is_target_modifier) { return false; } @@ -2175,6 +2321,7 @@ pub mod parse { pub(crate) fn parse_assert_incr_state( slot: &mut Option, v: Option<&str>, + _: bool, ) -> bool { *slot = match v { Some("loaded") => Some(IncrementalStateAssertion::Loaded), @@ -2184,7 +2331,11 @@ pub mod parse { true } - pub(crate) fn parse_rust_version(slot: &mut Option, v: Option<&str>) -> bool { + pub(crate) fn parse_rust_version( + slot: &mut Option, + v: Option<&str>, + _: bool, + ) -> bool { let Some(v) = v else { return false; }; From f4707ba2995234dfb840993f9c0629b10f8a47c5 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 17/29] sess: flags are both `-T` and `-C` Another big refactoring making all codegen flags both `-T` target modifiers and `-C` regular codegen flags, and enforcing that values match only when a flag is given as `-T`. Flags can be required to be target modifiers, optionally be target modifiers, or never be target modifiers. This commit no longer stores the entire `TargetOpts` struct, which no longer exists in metadata. Instead, produce a map from a new key enum (with one variant for each option) to the value set with `-T` and store that map. Values are converted to a `TargetModifierValue` type that stores only the types that target-modifier-compatible options - this is hypothetically better than `Box` that is not encodable and is large, or storing all of the option values. --- compiler/rustc_interface/src/tests.rs | 35 - compiler/rustc_metadata/src/creader.rs | 7 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 19 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 37 +- compiler/rustc_metadata/src/rmeta/mod.rs | 12 +- .../rustc_metadata/src/rmeta/parameterized.rs | 3 + compiler/rustc_session/src/config.rs | 21 +- compiler/rustc_session/src/diagnostics.rs | 55 +- compiler/rustc_session/src/options.rs | 669 ++++++++++-------- .../src/options/mitigation_coverage.rs | 4 +- src/librustdoc/config.rs | 17 +- src/librustdoc/core.rs | 4 +- src/librustdoc/doctest.rs | 2 +- 13 files changed, 502 insertions(+), 383 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index d08b93d696211..b98e3f464865a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -693,41 +693,6 @@ fn test_top_level_options_tracked_no_crate() { // tidy-alphabetical-end } -#[test] -fn test_target_options_tracking_hash() { - let reference = Options::default(); - let mut opts; - - macro_rules! tracked { - ($name: ident, $non_default_value: expr) => { - opts = reference.clone(); - assert_ne!(opts.target_opts.$name, $non_default_value); - opts.target_opts.$name = $non_default_value; - assert_different_hash(&reference, &opts); - }; - } - - // Make sure that changing a [TRACKED] option changes the hash. - // tidy-alphabetical-start - tracked!( - branch_protection, - Some(BranchProtection { - bti: true, - pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }), - gcs: true, - }) - ); - tracked!(fixed_x18, true); - tracked!(indirect_branch_cs_prefix, true); - tracked!(reg_struct_return, true); - tracked!(regparm, Some(3)); - tracked!(retpoline, true); - tracked!(retpoline_external_thunk, true); - tracked!(sanitizer, SanitizerSet::CFI); - tracked!(sanitizer_cfi_normalize_integers, Some(true)); - // tidy-alphabetical-end -} - #[test] fn test_unstable_options_tracking_hash() { let reference = Options::default(); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 3407da9a6709f..579b4d2d96340 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -345,22 +345,23 @@ impl CStore { pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>, krate: &Crate) { for flag_name in &tcx.sess.opts.cg.unsafe_allow_abi_mismatch { - if !rustc_session::config::TargetOptions::is_target_modifier(flag_name) { + if !tcx.sess.opts.cg.is_target_modifier(flag_name) { tcx.dcx().emit_err(diagnostics::UnknownTargetModifierUnsafeAllowed { span: krate.spans.inner_span.shrink_to_lo(), flag_name: flag_name.clone(), }); } } + for (_, data) in self.iter_crate_data() { if data.is_proc_macro_crate() { continue; } - tcx.sess.opts.target_opts.report_mismatched_flags_with_dep( + tcx.sess.opts.cg.report_mismatched_flags_with_dep( tcx.sess, krate.spans.inner_span.shrink_to_lo(), tcx.crate_name(LOCAL_CRATE), - data.target_opts(), + data.target_modifiers(), data.name(), ); } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index d2fea11dc4027..febc289906097 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -31,6 +31,7 @@ use rustc_middle::{bug, implement_ty_decoder}; use rustc_proc_macro::bridge::client::Client as ProcMacroClient; use rustc_serialize::opaque::MemDecoder; use rustc_serialize::{Decodable, Decoder}; +use rustc_session::config::CollectedTargetModifiers; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; use rustc_span::def_id::ModId; use rustc_span::hygiene::HygieneDecodeContext; @@ -920,9 +921,18 @@ impl MetadataBlob { write!(out, "\n")?; } + #[allow(rustc::potential_query_instability)] // `FxHashMap` order only for testing "target_modifiers" => { writeln!(out, "=Target modifiers=")?; - writeln!(out, "{}", root.target_options.ls())?; + let cg: FxHashMap<_, _> = root.target_modifiers.codegen.decode(self).collect(); + for (key, val) in cg { + writeln!(out, "-T{key}{val}")?; + } + let unstable: FxHashMap<_, _> = + root.target_modifiers.unstable.decode(self).collect(); + for (key, val) in unstable { + writeln!(out, "-T{key}{val}")?; + } } _ => { @@ -1982,8 +1992,11 @@ impl CrateMetadata { self.root.decode_denied_partial_mitigations(&self.blob).collect() } - pub(crate) fn target_opts(&self) -> &TargetOptions { - &self.root.target_options + pub(crate) fn target_modifiers(&self) -> CollectedTargetModifiers { + CollectedTargetModifiers { + codegen: self.root.target_modifiers.codegen.decode(&self.blob).collect(), + unstable: self.root.target_modifiers.unstable.decode(&self.blob).collect(), + } } /// Keep `new_extern_crate` if it looks better in diagnostics diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index a3f882461b536..a6952e2525d54 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -721,6 +721,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let source_map = stat!("source-map", || self.encode_source_map()); let denied_partial_mitigations = stat!("denied-partial-mitigations", || self .encode_enabled_denied_partial_mitigations()); + let target_modifiers = stat!("target-modifiers", || self.encode_target_modifiers()); let root = stat!("final", || { let attrs = tcx.hir_krate_attrs(); @@ -751,7 +752,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { panic_runtime: find_attr!(attrs, PanicRuntime), profiler_runtime: find_attr!(attrs, ProfilerRuntime), symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(), - target_options: tcx.sess.opts.target_opts.clone(), + target_modifiers, crate_deps, dylib_dependency_formats, @@ -2118,6 +2119,40 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.lazy_array(tcx.sess.gather_enabled_denied_partial_mitigations()) } + fn encode_target_modifiers(&mut self) -> TargetModifiers { + if self.is_proc_macro { + return TargetModifiers { + codegen: LazyArray::default(), + unstable: LazyArray::default(), + }; + } + + let tcx = self.tcx; + // JUSTIFICATION: Iteration order doesn't matter + #[allow(rustc::potential_query_instability)] + let codegen = self.lazy_array( + tcx.sess + .opts + .collected_options + .target_modifiers + .codegen + .iter() + .map(|(k, v)| (k.clone(), v.clone())), + ); + // JUSTIFICATION: Iteration order doesn't matter + #[allow(rustc::potential_query_instability)] + let unstable = self.lazy_array( + tcx.sess + .opts + .collected_options + .target_modifiers + .unstable + .iter() + .map(|(k, v)| (k.clone(), v.clone())), + ); + TargetModifiers { codegen, unstable } + } + fn encode_lib_features(&mut self) -> LazyArray<(Symbol, FeatureStability)> { empty_proc_macro!(self); let tcx = self.tcx; diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 95129d49122cb..c094bfb462476 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -38,7 +38,9 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util::Providers; use rustc_serialize::opaque::FileEncoder; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; -use rustc_session::config::{SymbolManglingVersion, TargetOptions}; +use rustc_session::config::{ + CodegenOptionsKey, SymbolManglingVersion, TargetModifierValue, UnstableOptionsKey, +}; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextKey}; use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Ident, Span, Symbol}; @@ -203,6 +205,12 @@ pub enum ProcMacroKind { Bang { name: String }, } +#[derive(MetadataEncodable, LazyDecodable)] +pub(crate) struct TargetModifiers { + codegen: LazyArray<(CodegenOptionsKey, TargetModifierValue)>, + unstable: LazyArray<(UnstableOptionsKey, TargetModifierValue)>, +} + /// Serialized crate metadata. /// /// This contains just enough information to determine if we should load the `CrateRoot` or not. @@ -294,7 +302,7 @@ pub(crate) struct CrateRoot { source_map: LazyTable>>, denied_partial_mitigations: LazyArray, - target_options: TargetOptions, + target_modifiers: TargetModifiers, compiler_builtins: bool, needs_allocator: bool, diff --git a/compiler/rustc_metadata/src/rmeta/parameterized.rs b/compiler/rustc_metadata/src/rmeta/parameterized.rs index 894077f78413f..8916da18b5102 100644 --- a/compiler/rustc_metadata/src/rmeta/parameterized.rs +++ b/compiler/rustc_metadata/src/rmeta/parameterized.rs @@ -133,6 +133,9 @@ trivially_parameterized_over_tcx! { rustc_middle::ty::Visibility, rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_middle::ty::fast_reject::SimplifiedType, + rustc_session::config::CodegenOptionsKey, + rustc_session::config::TargetModifierValue, + rustc_session::config::UnstableOptionsKey, rustc_session::config::mitigation_coverage::DeniedPartialMitigation, rustc_span::ExpnData, rustc_span::ExpnHash, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 15faf31122e02..f3b41a92a9213 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1426,7 +1426,6 @@ fn file_path_mapping( impl Default for Options { fn default() -> Options { - let target_opts = TargetOptions::default(); let unstable_opts = UnstableOptions::default(); // FIXME(Urgau): This is a hack that ideally shouldn't exist, but rustdoc @@ -1452,7 +1451,6 @@ impl Default for Options { target_triple: TargetTuple::from_tuple(host_tuple()), test: false, incremental: None, - target_opts, unstable_opts, prints: Vec::new(), cg: Default::default(), @@ -1482,9 +1480,8 @@ impl Default for Options { color: ColorConfig::Auto, logical_env: FxIndexMap::default(), verbose: false, - mitigation_coverage_map: Default::default(), jobs: Jobs { frontend: None, backend: None, linker: LinkerJobs::Default }, - metadata: Default::default(), + collected_options: Default::default(), } } } @@ -2751,14 +2748,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M .unwrap_or_else(|e| early_dcx.early_fatal(e)); let mut collected_options = Default::default(); - let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); - let mut target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); - TargetOptions::require_unstable_options( - early_dcx, - &collected_options.metadata, - unstable_opts.unstable_options, - ); // `-Zassumptions-on-binders` requires the next trait solver globally. Normalize after // parsing so the effective config is independent of flag order and so consumers that @@ -2806,6 +2796,11 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let output_types = parse_output_types(early_dcx, &unstable_opts, matches); let mut cg = CodegenOptions::build(early_dcx, matches, &mut collected_options); + CodegenOptions::require_unstable_options( + early_dcx, + &collected_options.metadata, + unstable_opts.unstable_options, + ); let (disable_local_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto( early_dcx, &output_types, @@ -3086,7 +3081,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M target_triple, test, incremental, - target_opts, unstable_opts, prints, cg, @@ -3116,9 +3110,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M color, logical_env, verbose, - mitigation_coverage_map: collected_options.mitigations, jobs, - metadata: collected_options.metadata, + collected_options, } } diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index b61c5ed9ac302..5e19b9fc05399 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -727,40 +727,45 @@ pub(crate) struct NativeTargetCpuNotAllowed<'a> { } #[derive(Diagnostic)] -#[diag("mixing `-{$prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`")] +#[diag( + "mixing `-{$target_modifier_prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`" +)] #[help( - "the `-{$prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" + "the `-{$target_modifier_prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" )] #[note( - "`-{$prefix}{$flag_name}={$local_value}` in this crate is incompatible with `-{$prefix}{$flag_name}={$extern_value}` in dependency `{$extern_crate}`" + "`-{$target_modifier_prefix}{$flag_name}{$local_value}` in this crate is incompatible with `-{$target_modifier_prefix}{$flag_name}{$extern_value}` in dependency `{$extern_crate}`" )] #[help( - "set `-{$prefix}{$flag_name}={$extern_value}` in this crate or `-{$prefix}{$flag_name}={$local_value}` in `{$extern_crate}`" + "set `-{$target_modifier_prefix}{$flag_name}{$extern_value}` in this crate or `-{$target_modifier_prefix}{$flag_name}{$local_value}` in `{$extern_crate}`" )] #[help( "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" )] -pub(crate) struct IncompatibleFlags { +pub(crate) struct IncompatibleFlagsMismatched { #[primary_span] pub span: Span, pub extern_crate: Symbol, pub local_crate: Symbol, - pub prefix: String, + pub prefix: &'static str, + pub target_modifier_prefix: &'static str, pub flag_name: String, pub local_value: String, pub extern_value: String, } #[derive(Diagnostic)] -#[diag("mixing `-{$prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`")] +#[diag( + "mixing `-{$target_modifier_prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`" +)] #[help( - "the `-{$prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" + "the `-{$target_modifier_prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" )] #[note( - "unset `-{$prefix}{$flag_name}` in this crate is incompatible with `-{$prefix}{$flag_name}={$extern_value}` in dependency `{$extern_crate}`" + "unset `-{$target_modifier_prefix}{$flag_name}` in this crate is incompatible with `-{$target_modifier_prefix}{$flag_name}{$extern_value}` in dependency `{$extern_crate}`" )] #[help( - "set `-{$prefix}{$flag_name}={$extern_value}` in this crate or unset `-{$prefix}{$flag_name}` in `{$extern_crate}`" + "set `-{$target_modifier_prefix}{$flag_name}{$extern_value}` in this crate, unset `-{$target_modifier_prefix}{$flag_name}` in `{$extern_crate}`, or use `-{$prefix}{$flag_name}` in `{$extern_crate}`" )] #[help( "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" @@ -770,11 +775,39 @@ pub(crate) struct IncompatibleFlagsUnsetLocally { pub span: Span, pub extern_crate: Symbol, pub local_crate: Symbol, - pub prefix: String, + pub prefix: &'static str, + pub target_modifier_prefix: &'static str, pub flag_name: String, pub extern_value: String, } +#[derive(Diagnostic)] +#[diag( + "mixing `-{$target_modifier_prefix}{$flag_name}` will cause an ABI mismatch in crate `{$local_crate}`" +)] +#[help( + "the `-{$target_modifier_prefix}{$flag_name}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely" +)] +#[note( + "unset `-{$target_modifier_prefix}{$flag_name}` in `{$extern_crate}` is incompatible with `-{$target_modifier_prefix}{$flag_name}{$local_value}` in this crate" +)] +#[help( + "set `-{$target_modifier_prefix}{$flag_name}{$local_value}` in `{$extern_crate}`, unset `-{$target_modifier_prefix}{$flag_name}` in this crate, or use `-{$prefix}{$flag_name}` in this crate instead" +)] +#[help( + "if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error" +)] +pub(crate) struct IncompatibleFlagsUnsetExternally { + #[primary_span] + pub span: Span, + pub extern_crate: Symbol, + pub local_crate: Symbol, + pub prefix: &'static str, + pub target_modifier_prefix: &'static str, + pub flag_name: String, + pub local_value: String, +} + #[derive(Diagnostic)] #[diag("`target-cpu` must be set with `-Ttarget-cpu` for this target")] pub(crate) struct TargetCpuNeedsTargetModifierOpt; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8efa3ed14618c..aba36a6e05311 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1,12 +1,12 @@ use std::collections::BTreeMap; use std::num::{IntErrorKind, NonZero}; use std::path::PathBuf; -use std::str; +use std::{fmt, str}; use rustc_abi::Align; use rustc_ast::attr::version::RustcVersion; use rustc_attr_ir::CollapseMacroDebuginfo; -use rustc_data_structures::fx::FxIndexMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::profiling::TimePassesFormat; use rustc_data_structures::stable_hash::StableHasher; use rustc_errors::{ColorConfig, TerminalUrl}; @@ -77,7 +77,6 @@ pub struct OptionMetadata { #[derive(Clone, Default)] pub struct OptionsMetadata { pub(crate) codegen: CodegenOptionsMetadata, - pub(crate) target: TargetOptionsMetadata, pub(crate) unstable: UnstableOptionsMetadata, } @@ -100,8 +99,7 @@ macro_rules! top_level_options { $(#[$attr])* pub $opt: $t, )* - pub mitigation_coverage_map: mitigation_coverage::MitigationCoverageMap, - pub metadata: OptionsMetadata, + pub collected_options: CollectedOptions, } impl Options { @@ -196,7 +194,6 @@ top_level_options!( /// directory to store intermediate results. incremental: Option [UNTRACKED], - target_opts: TargetOptions [SUBSTRUCT], unstable_opts: UnstableOptions [SUBSTRUCT], prints: Vec [UNTRACKED], cg: CodegenOptions [SUBSTRUCT], @@ -275,16 +272,169 @@ top_level_options!( } ); -#[derive(Default)] +/// Enum of types that command-line options can take - eventually stored into cross-crate metadata +/// instead of a `Box`. +#[derive(BlobDecodable, Clone, Encodable, PartialEq)] +pub enum TargetModifierValue { + Bool(bool), + U32(u32), + Usize(usize), + BranchProtection(BranchProtection), + Sanitizers(SanitizerSet), +} + +impl fmt::Display for TargetModifierValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Bool(_) => write!(f, ""), + Self::U32(val) => write!(f, "={val}"), + Self::Usize(val) => write!(f, "={val}"), + Self::BranchProtection(val) => write!(f, "={val}"), + Self::Sanitizers(val) => write!(f, "={val}"), + } + } +} + +macro_rules! noop_target_modifier_ty { + ($($ty:ty => $ctor:expr,)+) => { + $( + impl From<$ty> for TargetModifierValue { + fn from(value: $ty) -> Self { + $ctor(value) + } + } + )+ + } +} + +noop_target_modifier_ty!( + // tidy-alphabetical-start + SanitizerSet => Self::Sanitizers, + bool => Self::Bool, + u32 => Self::U32, + usize => Self::Usize, + // tidy-alphabetical-end +); + +macro_rules! opt_or_default_target_modifier_ty { + ($($ty:ty => $ctor:expr,)+) => { + $( + impl From> for TargetModifierValue { + fn from(value: Option<$ty>) -> Self { + $ctor(value.unwrap_or_default()) + } + } + )+ + } +} + +opt_or_default_target_modifier_ty!( + // tidy-alphabetical-start + BranchProtection => Self::BranchProtection, + String => Self::String, + bool => Self::Bool, + u32 => Self::U32, + usize => Self::Usize, + // tidy-alphabetical-end +); + +macro_rules! unsupported_target_modifier_ty { + ($($ty:ty,)*) => { + $( + impl From<$ty> for TargetModifierValue { + fn from(_: $ty) -> Self { + unimplemented!("type not supported for a target modifier: {}", stringify!($ty)) + } + } + )+ + } +} + +unsupported_target_modifier_ty!( + // tidy-alphabetical-start + (), + AnnotateMoves, + CFGuard, + CFProtection, + CollapseMacroDebuginfo, + CoverageOptions, + DebugInfo, + DebugInfoCompression, + DumpMonoStatsFormat, + FmtDebug, + FramePointer, + FunctionReturn, + InliningThreshold, + InstrumentCoverage, + InstrumentMcount, + LinkSelfContained, + LinkerFeaturesCli, + LinkerPluginLto, + LocationDetail, + LtoCli, + MirIncludeSpans, + MirStripDebugInfo, + NextSolverConfig, + OnBrokenPipe, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option>, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option, + Option>, + Option, + Option, + PanicStrategy, + Passes, + PatchableFunctionEntry, + Polonius, + ProcMacroExecutionStrategy, + SplitDwarfKind, + StackProtector, + String, + Strip, + SwitchWithOptPath, + TerminalUrl, + TimePassesFormat, + Vec<(String, bool)>, + Vec<(String, u32, String)>, + Vec, + Vec, + Vec, + // tidy-alphabetical-end +); + +#[derive(Clone, Default)] +pub struct CollectedTargetModifiers { + pub codegen: FxHashMap, + pub unstable: FxHashMap, +} + +#[derive(Clone, Default)] pub struct CollectedOptions { pub mitigations: mitigation_coverage::MitigationCoverageMap, pub metadata: OptionsMetadata, + pub target_modifiers: CollectedTargetModifiers, } macro_rules! setter_for { // the allow/deny-mitigations options use collected/index instead of the cg, since they // work across option groups - (allow_partial_mitigations, $struct_name:ident, $group_name:ident, $parse:ident) => { + (allow_partial_mitigations, $struct_name:ident, $group_name:ident, $key_name:ident, $parse:ident) => { pub(super) fn allow_partial_mitigations( _cg: &mut super::$struct_name, collected: &mut super::CollectedOptions, @@ -295,7 +445,7 @@ macro_rules! setter_for { collected.mitigations.handle_allowdeny_mitigation_option(v, index, true) } }; - (deny_partial_mitigations, $struct_name:ident, $group_name:ident, $parse:ident) => { + (deny_partial_mitigations, $struct_name:ident, $group_name:ident, $key_name:ident, $parse:ident) => { pub(super) fn deny_partial_mitigations( _cg: &mut super::$struct_name, collected: &mut super::CollectedOptions, @@ -306,7 +456,7 @@ macro_rules! setter_for { collected.mitigations.handle_allowdeny_mitigation_option(v, index, false) } }; - ($opt:ident, $struct_name:ident, $group_name:ident, $parse:ident) => { + ($opt:ident, $struct_name:ident, $group_name:ident, $key_name:ident, $parse:ident) => { pub(super) fn $opt( cg: &mut super::$struct_name, collected: &mut super::CollectedOptions, @@ -315,7 +465,14 @@ macro_rules! setter_for { is_target_modifier: bool, ) -> bool { collected.metadata.$group_name.$opt.is_set = v.is_some(); - super::parse::$parse(&mut redirect_field!(cg.$opt), v, is_target_modifier) + let res = super::parse::$parse(&mut redirect_field!(cg.$opt), v, is_target_modifier); + if is_target_modifier { + let _ = collected + .target_modifiers + .$group_name + .insert(super::$key_name::$opt, redirect_field!(cg.$opt).clone().into()); + } + res } }; } @@ -333,9 +490,11 @@ macro_rules! options { $(#[$struct_attr:meta])* $struct_name:ident, // e.g. `UnstableOptions` $metadata_name: ident, // e.g. `UnstableOptionsMetadata` + $key_name: ident, // e.g. `UnstableOptionsKey` $opt_descs_var:ident, // e.g. `Z_OPTIONS` $opt_mod_name:ident, // e.g. `dbopts` $prefix:expr, // e.g. `-Z` + $target_modifier_prefix:expr, // e.g. `Some("-T")` or `None` $group_name:ident, // e.g. `unstable` $( @@ -345,6 +504,7 @@ macro_rules! options { $parse:ident, [$dep_tracking_marker:ident] $( { MITIGATION: $mitigation_variant:ident } )? + $( { TARGET_MODIFIER: $target_modifier_filter:ident } )? , $desc:literal $(, removed: $removed:ident )? @@ -368,6 +528,25 @@ macro_rules! options { )* } + #[allow(nonstandard_style)] + #[derive(BlobDecodable, Copy, Clone, Eq, Encodable, Hash, PartialEq, PartialOrd, Ord)] + #[repr(u32)] + pub enum $key_name { + $( + $opt, + )* + } + + impl fmt::Display for $key_name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $( + Self::$opt => write!(f, "{}", stringify!($opt).replace('_', "-")) + ),* + } + } + } + impl Default for $struct_name { fn default() -> $struct_name { $struct_name { @@ -390,6 +569,7 @@ macro_rules! options { collected_options, $opt_descs_var, $prefix, + $target_modifier_prefix, stringify!($group_name) ) } @@ -418,6 +598,91 @@ macro_rules! options { ); hasher.finish() } + + pub fn require_unstable_options( + _early_dcx: &EarlyDiagCtxt, + _meta: &OptionsMetadata, + _unstable_opts: bool + ) { + $( + require_unstable_options!( + $opt, + $group_name, + [$dep_tracking_marker], + (_early_dcx, _meta, _unstable_opts) + ); + )* + } + + pub fn is_target_modifier(&self, flag_name: &str) -> bool { + let flag_name = flag_name.replace('-', "_").to_string(); + match $opt_descs_var.iter().find(|opt_desc| opt_desc.name == flag_name) { + Some(OptionDesc { target_modifier_filter: Some(TargetModifierFilter::Never), .. }) => false, + Some(_) => true, + None => false, + } + } + + pub fn report_mismatched_flags_with_dep( + &self, + sess: &crate::Session, + span: rustc_span::Span, + local_crate: rustc_span::Symbol, + extern_opts: CollectedTargetModifiers, + extern_crate: rustc_span::Symbol + ) { + let allowed_flag_mismatches = &sess.opts.cg.unsafe_allow_abi_mismatch; + let compare = |local_value: Option<&TargetModifierValue>, extern_value: Option<&TargetModifierValue>, flag_name| { + match (local_value, extern_value) { + (Some(local_value), Some(extern_value)) if local_value != extern_value => { + sess.dcx().emit_err(crate::diagnostics::IncompatibleFlagsMismatched { + span, + local_crate, + extern_crate, + prefix: $prefix, + target_modifier_prefix: $target_modifier_prefix.expect("mismatch w/out prefix"), + flag_name, + local_value: local_value.to_string(), + extern_value: extern_value.to_string(), + }); + }, + (None, Some(extern_value)) => { + sess.dcx().emit_err(crate::diagnostics::IncompatibleFlagsUnsetLocally { + span, + local_crate, + extern_crate, + prefix: $prefix, + target_modifier_prefix: $target_modifier_prefix.expect("mismatch w/out prefix"), + flag_name, + extern_value: extern_value.to_string(), + }); + }, + (Some(local_value), None) => { + sess.dcx().emit_err(crate::diagnostics::IncompatibleFlagsUnsetExternally { + span, + local_crate, + extern_crate, + prefix: $prefix, + target_modifier_prefix: $target_modifier_prefix.expect("mismatch w/out prefix"), + flag_name, + local_value: local_value.to_string(), + }); + }, + (Some(_), Some(_)) => { /* no-op, matching flag values */ } + (None, None) => { /* no-op, neither flag is passed as a target modifier */ } + } + }; + + $( + let flag_name = stringify!($opt).replace('_', "-").to_string(); + let allowed = allowed_flag_mismatches.contains(&flag_name); + if !allowed { + let local_value = sess.opts.collected_options.target_modifiers.$group_name.get(&$key_name::$opt); + let extern_value = extern_opts.$group_name.get(&$key_name::$opt); + compare(local_value, extern_value, flag_name); + } + )* + } } pub const $opt_descs_var: OptionDescrs<$struct_name> = &[ @@ -428,6 +693,7 @@ macro_rules! options { type_desc: desc::$parse, desc: $desc, removed: None $( .or(Some(RemovedOption::$removed)) )?, + target_modifier_filter: None $( .or(Some(TargetModifierFilter::$target_modifier_filter)) )?, mitigation: None $( .or(Some( mitigation_coverage::DeniedPartialMitigationKind::$mitigation_variant )))?, @@ -437,7 +703,7 @@ macro_rules! options { mod $opt_mod_name { $( - setter_for!($opt, $struct_name, $group_name, $parse); + setter_for!($opt, $struct_name, $group_name, $key_name, $parse); )* } } @@ -462,181 +728,6 @@ macro_rules! require_unstable_options { ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; } -trait TargetModifierOptionValue { - fn to_string_for_diag(&self) -> String; -} - -impl TargetModifierOptionValue for bool { - fn to_string_for_diag(&self) -> String { - self.to_string() - } -} - -impl TargetModifierOptionValue for u32 { - fn to_string_for_diag(&self) -> String { - self.to_string() - } -} - -impl TargetModifierOptionValue for Vec<(PointerAuthOption, bool)> { - fn to_string_for_diag(&self) -> String { - let mut parts = Vec::new(); - for (opt, pos) in self { - let polarity = if *pos { "+" } else { "-" }; - parts.push(format!("{polarity}{opt}")); - } - parts.join(",") - } -} - -impl TargetModifierOptionValue for String { - fn to_string_for_diag(&self) -> String { - self.to_string() - } -} - -impl TargetModifierOptionValue for BranchProtection { - fn to_string_for_diag(&self) -> String { - self.to_string() - } -} - -impl TargetModifierOptionValue for SanitizerSet { - fn to_string_for_diag(&self) -> String { - self.to_string() - } -} - -impl TargetModifierOptionValue for Option { - fn to_string_for_diag(&self) -> String { - match self { - Some(v) => v.to_string_for_diag(), - None => "".to_string(), - } - } -} - -macro_rules! target_modifier_options { - ( - $struct_name:ident, // e.g. `UnstableOptions` - $metadata_name: ident, // e.g. `UnstableOptionsMetadata` - $opt_descs_var:ident, // e.g. `Z_OPTIONS` - $opt_mod_name:ident, // e.g. `dbopts` - $prefix:expr, // e.g. `-Z` - $group_name:ident, // e.g. `unstable` - - $( - $(#[$attr:meta])* - $opt:ident : $t:ty = ( - $init:expr, - $parse:ident, - [$dep_tracking_marker:ident], - $desc:literal - $(, removed: $removed:ident )? - ), - )* - ) => { - options! { - #[derive(Encodable, BlobDecodable)] - $struct_name, - $metadata_name, - $opt_descs_var, - $opt_mod_name, - $prefix, - $group_name, - - $( - $(#[$attr])* - $opt : $t = ( - $init, - $parse, - [$dep_tracking_marker], - $desc - $(, removed: $removed )? - ), - )* - } - - impl $struct_name { - pub fn ls(&self) -> String { - let mut out = Vec::new(); - $( - out.push(format!( - "-{prefix}{opt}={val} [{val:?}]", - prefix=$prefix, - opt=stringify!($opt).replace('_', "-"), - val=self.$opt.to_string_for_diag()) - ); - )* - out.join("\n") - } - - pub fn require_unstable_options( - early_dcx: &EarlyDiagCtxt, - meta: &OptionsMetadata, - unstable_opts: bool - ) { - $( - require_unstable_options!( - $opt, - $group_name, - [$dep_tracking_marker], - (early_dcx, meta, unstable_opts) - ); - )* - } - - pub fn is_target_modifier(name: &str) -> bool { - let name = name.replace('-', "_"); - match name.as_str() { - $(stringify!($opt))|* => true, - _ => false, - } - } - - pub fn report_mismatched_flags_with_dep( - &self, - sess: &crate::Session, - span: rustc_span::Span, - local_crate: rustc_span::Symbol, - extern_opts: &Self, - extern_crate: rustc_span::Symbol - ) { - let allowed_flag_mismatches = &sess.opts.cg.unsafe_allow_abi_mismatch; - $( - let flag_name = stringify!($opt).replace('_', "-").to_string(); - let allowed = allowed_flag_mismatches.contains(&flag_name); - if !allowed && self.$opt != extern_opts.$opt { - if sess.opts.metadata.$group_name.$opt.is_set { - // If `self` set and not matching, `extern_opts` might have set `$opt` - // or might not, but the guidance is the same regardless - sess.dcx().emit_err(crate::diagnostics::IncompatibleFlags { - span, - local_crate, - extern_crate, - prefix: $prefix.to_string(), - flag_name, - local_value: self.$opt.to_string_for_diag(), - extern_value: extern_opts.$opt.to_string_for_diag(), - }); - } else { - // If `self` unset and not matching, assume `extern_opts` set `$opt` - sess.dcx().emit_err(crate::diagnostics::IncompatibleFlagsUnsetLocally { - span, - local_crate, - extern_crate, - prefix: $prefix.to_string(), - flag_name, - extern_value: extern_opts.$opt.to_string_for_diag(), - }); - } - } - )* - } - } - } -} - impl CodegenOptions { // JUSTIFICATION: defn of the suggested wrapper fn #[allow(rustc::bad_opt_access)] @@ -675,6 +766,13 @@ enum RemovedOption { Err, } +enum TargetModifierFilter { + // Option cannot be passed as a target modifier + Never, + // Option can only be passed as a target modifier + Only, +} + pub struct OptionDesc { name: &'static str, setter: OptionSetter, @@ -683,6 +781,7 @@ pub struct OptionDesc { // description for option from options table desc: &'static str, removed: Option, + target_modifier_filter: Option, mitigation: Option, } @@ -702,71 +801,98 @@ fn build_options( collected_options: &mut CollectedOptions, descrs: OptionDescrs, prefix: &str, + target_modifier_prefix: Option<&str>, outputname: &str, ) -> O { let mut op = O::default(); - for (index, option) in matches.opt_strs_pos(prefix) { - let (key, value) = match option.split_once('=') { - None => (option, None), - Some((k, v)) => (k.to_string(), Some(v)), - }; + let mut build_with_prefix = |current_prefix: &str, is_target_modifier: bool| { + for (index, option) in matches.opt_strs_pos(current_prefix) { + let (key, value) = match option.split_once('=') { + None => (option, None), + Some((k, v)) => (k.to_string(), Some(v)), + }; - let option_to_lookup = key.replace('-', "_"); - match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) { - Some(OptionDesc { name: _, setter, type_desc, desc, removed, mitigation }) => { - if let Some(removed) = removed { - // deprecation works for prefixed options only - assert!(!prefix.is_empty()); - match removed { - RemovedOption::Warn => { - early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}")) - } - RemovedOption::Err => { - early_dcx.early_fatal(format!("`-{prefix} {key}`: {desc}")) + let option_to_lookup = key.replace('-', "_"); + match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) { + Some(OptionDesc { + name: _, + setter, + type_desc, + desc, + removed, + mitigation, + target_modifier_filter, + }) => { + if let Some(removed) = removed { + // deprecation works for prefixed options only + assert!(!current_prefix.is_empty()); + match removed { + RemovedOption::Warn => { + early_dcx.early_warn(format!("`-{current_prefix} {key}`: {desc}")) + } + RemovedOption::Err => { + early_dcx.early_fatal(format!("`-{current_prefix} {key}`: {desc}")) + } } } - } - if !setter(&mut op, collected_options, value, index, false) { - match value { - None => early_dcx.early_fatal( - format!( - "{outputname} option `{key}` requires {type_desc} (`-{prefix} {key}=`)" + match target_modifier_filter { + Some(TargetModifierFilter::Only) if !is_target_modifier => { + early_dcx.early_fatal(format!("`-{current_prefix} {key}`: can only be passed with `-{}`", target_modifier_prefix.expect("option only allowed with target modifier but substruct does not have a target modifier variant"))) + }, + Some(TargetModifierFilter::Never) if is_target_modifier => { + early_dcx.early_fatal(format!("`-{current_prefix} {key}`: can only be passed with `-{}`", prefix)) + }, + _ => (), + } + if !setter(&mut op, collected_options, value, index, is_target_modifier) { + match value { + None => early_dcx.early_fatal( + format!( + "{outputname} option `{key}` requires {type_desc} (`-{current_prefix} {key}=`)" + ), ), - ), - Some(value) => early_dcx.early_fatal( - format!( - "incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected" + Some(value) => early_dcx.early_fatal( + format!( + "incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected" + ), ), - ), + } + } + if let Some(mitigation) = mitigation { + collected_options.mitigations.reset_mitigation(*mitigation, index); } } - if let Some(mitigation) = mitigation { - collected_options.mitigations.reset_mitigation(*mitigation, index); - } - } - None => { - let mut error = - early_dcx.early_struct_fatal(format!("unknown {outputname} option: `{key}`")); - let max_dist = option_to_lookup.chars().count().max(3) / 3; - if let Some(option) = descrs - .iter() - .filter(|option| option.removed.is_none()) - .filter_map(|option| { - edit_distance(&option_to_lookup, option.name, max_dist) - .map(|dist| (dist, option)) - }) - .min_by_key(|(dist, _)| *dist) - .map(|(_, option)| option) - { - let name = option.name.replace('_', "-"); - let value = - if option.type_desc == desc::parse_no_value { "" } else { "=" }; - error.help(format!("you might have meant to use `-{prefix} {name}{value}`")); + None => { + let mut error = early_dcx + .early_struct_fatal(format!("unknown {outputname} option: `{key}`")); + let max_dist = option_to_lookup.chars().count().max(3) / 3; + if let Some(option) = descrs + .iter() + .filter(|option| option.removed.is_none()) + .filter_map(|option| { + edit_distance(&option_to_lookup, option.name, max_dist) + .map(|dist| (dist, option)) + }) + .min_by_key(|(dist, _)| *dist) + .map(|(_, option)| option) + { + let name = option.name.replace('_', "-"); + let value = + if option.type_desc == desc::parse_no_value { "" } else { "=" }; + error + .help(format!("you might have meant to use `-{prefix} {name}{value}`")); + } + error.emit() } - error.emit() } } + }; + + build_with_prefix(prefix, false); + if let Some(prefix) = target_modifier_prefix { + build_with_prefix(prefix, true); } + op } @@ -2349,7 +2475,8 @@ pub mod parse { } options! { - CodegenOptions, CodegenOptionsMetadata, CG_OPTIONS, cgopts, "C", codegen, + CodegenOptions, CodegenOptionsMetadata, CodegenOptionsKey, + CG_OPTIONS, cgopts, "C", Some("T"), codegen, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs @@ -2383,7 +2510,7 @@ options! { "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), embed_bitcode: bool = (true, parse_bool, [TRACKED], "emit bitcode in rlibs (default: yes)"), - extra_filename: String = (String::new(), parse_string, [UNTRACKED], + extra_filename: String = (String::new(), parse_string, [UNTRACKED] { TARGET_MODIFIER: Never }, "extra data to put in each output filename"), force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED], "force use of the frame pointers"), @@ -2497,68 +2624,8 @@ options! { // - src/doc/rustc/src/codegen-options/index.md } -target_modifier_options! { - TargetOptions, TargetOptionsMetadata, T_OPTIONS, topts, "T", target, - - // tidy-alphabetical-start - #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] - branch_protection: Option = (None, parse_branch_protection, [TRACKED_UNSTABLE], - "set options for branch target identification and pointer authentication on AArch64"), - fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE], - "make the x18 register reserved on AArch64 (default: no)"), - indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE], - "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), - llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED_UNSTABLE], - "enable/disable LLVM-level target features. \ - This feature is unsafe and can cause ABI issues and compiler crashes, \ - because LLVM does not support all target feature combinations."), - pointer_authentication: Vec<(PointerAuthOption, bool)> = ( - Vec::new(), - parse_pointer_authentication_list_with_polarity, - [TRACKED_UNSTABLE], - "A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options: - `aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch - `auth-traps` - trap immediately on pointer authentication failure - `calls` - enable signing and authentication of all indirect calls - `elf-got` - enable authentication of pointers from GOT (ELF only) - `function-pointer-type-discrimination` - enable type discrimination on C function pointers - `indirect-gotos` - enable signing and authentication of indirect goto targets - `init-fini` - enable signing of function pointers in init/fini arrays - `init-fini-address-discrimination` - enable address discrimination in init/fini arrays - `intrinsics` - pointer authentication intrinsics - `return-addresses` - enable signing and authentication of return addresses - `typeinfo-vt-ptr-discrimination - incorporate type and address discrimination in authenticated vtable pointers for std::type_info - `vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers - `vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers - Example: `-Zpointer-authentication=+calls,-init-fini`."), - reg_struct_return: bool = (false, parse_bool, [TRACKED_UNSTABLE], - "On x86-32 targets, it overrides the default ABI to return small structs in registers."), - regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE], - "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ - in registers EAX, EDX, and ECX instead of on the stack for\ - \"C\", \"cdecl\", and \"stdcall\" fn."), - retpoline: bool = (false, parse_bool, [TRACKED_UNSTABLE], - "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), - retpoline_external_thunk: bool = (false, parse_bool, [TRACKED_UNSTABLE], - "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ - target features (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] - sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_target, [TRACKED_UNSTABLE], - "use a sanitizer"), - sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED_UNSTABLE], - "enable normalizing integer types (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::target_cpu` instead of this field")] - target_cpu: Option = (None, parse_opt_string, [TRACKED], - "select target processor (`rustc --print target-cpus` for details)"), - // tidy-alphabetical-end - - // If you add a new option, please update: - // - compiler/rustc_interface/src/tests.rs - // - src/doc/rustc/src/target-options/index.md (for stable options) -} - options! { - UnstableOptions, UnstableOptionsMetadata, Z_OPTIONS, dbopts, "Z", unstable, + UnstableOptions, UnstableOptionsMetadata, UnstableOptionsKey, Z_OPTIONS, dbopts, "Z", None, unstable, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs diff --git a/compiler/rustc_session/src/options/mitigation_coverage.rs b/compiler/rustc_session/src/options/mitigation_coverage.rs index dbe989100d567..225dad4550e69 100644 --- a/compiler/rustc_session/src/options/mitigation_coverage.rs +++ b/compiler/rustc_session/src/options/mitigation_coverage.rs @@ -227,7 +227,9 @@ impl Options { .all_denied_partial_mitigations() .filter(|mitigation| mitigation.allowed_by_default_at(edition)) .collect(); - for (kind, MitigationStatus { index: _, allowed }) in &self.mitigation_coverage_map.map { + for (kind, MitigationStatus { index: _, allowed }) in + &self.collected_options.mitigations.map + { match allowed { Some(true) => { result.insert(*kind); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 6e1bac7645b89..615b51a97fa31 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -8,9 +8,9 @@ use std::{fmt, io}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::DiagCtxtHandle; use rustc_session::config::{ - self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns, - OutFileName, Sysroot, TargetOptions, UnstableOptions, get_cmd_lint_options, nightly_options, - parse_crate_types_from_list, parse_externs, parse_target_triple, + self, CodegenOptions, CollectedOptions, CrateType, ErrorOutputType, Externs, Input, + JsonUnusedExterns, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, + nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple, }; use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; @@ -88,14 +88,14 @@ pub(crate) struct Options { pub(crate) codegen_options: CodegenOptions, /// Codegen options strings to hand to the compiler. pub(crate) codegen_options_strs: Vec, - /// Target options to hand to the compiler. - pub(crate) target_opts: TargetOptions, /// Target options strings to hand to the compiler. pub(crate) target_opts_strs: Vec, /// Unstable (`-Z`) options to pass to the compiler. pub(crate) unstable_opts: UnstableOptions, /// Unstable (`-Z`) options strings to pass to the compiler. pub(crate) unstable_opts_strs: Vec, + /// Side-table populated during option parsing + pub(crate) collected_options: CollectedOptions, /// The target used to compile the crate against. pub(crate) target: TargetTuple, /// Edition used when reading the crate. Defaults to "2015". Also used by default when @@ -412,10 +412,9 @@ impl Options { let mut collected_options = Default::default(); let codegen_options = CodegenOptions::build(early_dcx, matches, &mut collected_options); let unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); - let target_opts = TargetOptions::build(early_dcx, matches, &mut collected_options); - TargetOptions::require_unstable_options( + CodegenOptions::require_unstable_options( early_dcx, - &collected_options.metadata, + &collected_options, #[allow(rustc::bad_opt_access)] unstable_opts.unstable_options, ); @@ -940,10 +939,10 @@ impl Options { check_cfgs, codegen_options, codegen_options_strs, - target_opts, target_opts_strs, unstable_opts, unstable_opts_strs, + collected_options, target, edition, sysroot, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 3561f44aa008d..6c1b531db7e93 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -218,7 +218,7 @@ pub(crate) fn create_config( check_cfgs, codegen_options, unstable_opts, - target_opts, + collected_options, target, edition, sysroot, @@ -274,13 +274,13 @@ pub(crate) fn create_config( lint_opts, lint_cap, cg: codegen_options, + collected_options, externs, target_triple: target, unstable_features: UnstableFeatures::from_environment(crate_name.as_deref()), actually_rustdoc: true, resolve_doc_links, unstable_opts, - target_opts, error_format, diagnostic_width, edition, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 76a8d5c275d97..395c23a7aca5d 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -175,9 +175,9 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions crate_name: options.crate_name.clone(), remap_path_prefix: options.remap_path_prefix.clone(), remap_path_scope: options.remap_path_scope.clone(), - target_opts: options.target_opts.clone(), unstable_opts: options.unstable_opts.clone(), error_format: options.error_format.clone(), + collected_options: options.collected_options.clone(), ..config::Options::default() }; From 6ddfa633a3716957ad1e9ab5271c98e521790d13 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 27 Jul 2026 14:07:50 +0000 Subject: [PATCH 18/29] sess: reimplement `is_set` using `$key_name` Re-using the key enum that was introduced in the previous commit to track options being set using a `HashSet` rather than a new struct with boolean fields. --- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/options.rs | 67 +++++++++++---------------- 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f3b41a92a9213..5ea67cb4c6875 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2798,7 +2798,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let mut cg = CodegenOptions::build(early_dcx, matches, &mut collected_options); CodegenOptions::require_unstable_options( early_dcx, - &collected_options.metadata, + &collected_options, unstable_opts.unstable_options, ); let (disable_local_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto( diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index aba36a6e05311..fb59ca5d0f262 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -6,7 +6,7 @@ use std::{fmt, str}; use rustc_abi::Align; use rustc_ast::attr::version::RustcVersion; use rustc_attr_ir::CollapseMacroDebuginfo; -use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::profiling::TimePassesFormat; use rustc_data_structures::stable_hash::StableHasher; use rustc_errors::{ColorConfig, TerminalUrl}; @@ -67,19 +67,6 @@ macro_rules! hash_substruct { pub mod mitigation_coverage; -/// Metadata associated with an option -#[derive(Clone, Default)] -pub struct OptionMetadata { - /// Was this option set by the user? - pub(crate) is_set: bool, -} - -#[derive(Clone, Default)] -pub struct OptionsMetadata { - pub(crate) codegen: CodegenOptionsMetadata, - pub(crate) unstable: UnstableOptionsMetadata, -} - macro_rules! top_level_options { ( $(#[$top_level_attr:meta])* @@ -424,10 +411,16 @@ pub struct CollectedTargetModifiers { pub unstable: FxHashMap, } +#[derive(Clone, Default)] +pub struct CollectedIsSet { + pub codegen: FxHashSet, + pub unstable: FxHashSet, +} + #[derive(Clone, Default)] pub struct CollectedOptions { pub mitigations: mitigation_coverage::MitigationCoverageMap, - pub metadata: OptionsMetadata, + pub is_set: CollectedIsSet, pub target_modifiers: CollectedTargetModifiers, } @@ -464,7 +457,7 @@ macro_rules! setter_for { _index: usize, is_target_modifier: bool, ) -> bool { - collected.metadata.$group_name.$opt.is_set = v.is_some(); + collected.is_set.$group_name.insert(super::$key_name::$opt); let res = super::parse::$parse(&mut redirect_field!(cg.$opt), v, is_target_modifier); if is_target_modifier { let _ = collected @@ -489,7 +482,6 @@ macro_rules! options { ( $(#[$struct_attr:meta])* $struct_name:ident, // e.g. `UnstableOptions` - $metadata_name: ident, // e.g. `UnstableOptionsMetadata` $key_name: ident, // e.g. `UnstableOptionsKey` $opt_descs_var:ident, // e.g. `Z_OPTIONS` $opt_mod_name:ident, // e.g. `dbopts` @@ -521,13 +513,6 @@ macro_rules! options { )* } - #[derive(Clone, Default)] - pub struct $metadata_name { - $( - pub $opt: OptionMetadata, - )* - } - #[allow(nonstandard_style)] #[derive(BlobDecodable, Copy, Clone, Eq, Encodable, Hash, PartialEq, PartialOrd, Ord)] #[repr(u32)] @@ -601,15 +586,16 @@ macro_rules! options { pub fn require_unstable_options( _early_dcx: &EarlyDiagCtxt, - _meta: &OptionsMetadata, + _collected_options: &CollectedOptions, _unstable_opts: bool ) { $( require_unstable_options!( $opt, $group_name, + $key_name, [$dep_tracking_marker], - (_early_dcx, _meta, _unstable_opts) + (_early_dcx, _collected_options, _unstable_opts) ); )* } @@ -710,22 +696,22 @@ macro_rules! options { } macro_rules! require_unstable_options { - ($opt_name:ident, $group_name:ident, [UNTRACKED], - ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; - ($opt_name:ident, $group_name:ident, [TRACKED], - ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; - ($opt_name:ident, $group_name:ident, [TRACKED_UNSTABLE], - ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{ - if $meta.$group_name.$opt_name.is_set && !$unstable_opts { + ($opt:ident, $group_name:ident, $key_name:ident, [UNTRACKED], + ($early_dcx:ident, $collected_options:ident, $unstable_opts:ident)) => {{}}; + ($opt:ident, $group_name:ident, $key_name:ident, [TRACKED], + ($early_dcx:ident, $collected_options:ident, $unstable_opts:ident)) => {{}}; + ($opt:ident, $group_name:ident, $key_name:ident, [TRACKED_UNSTABLE], + ($early_dcx:ident, $collected_options:ident, $unstable_opts:ident)) => {{ + if $collected_options.is_set.$group_name.contains(&$key_name::$opt) && !$unstable_opts { $early_dcx - .early_err(format!("`-T{}` requires `-Zunstable-options`", stringify!($opt_name))) + .early_err(format!("`-T{}` requires `-Zunstable-options`", stringify!($opt))) .raise_fatal(); } }}; - ($opt_name:ident, $group_name:ident, [TRACKED_NO_CRATE_HASH], - ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; - ($opt_name:ident, $group_name:ident, [SUBSTRUCT], - ($early_dcx:ident, $meta:ident, $unstable_opts:ident)) => {{}}; + ($opt:ident, $group_name:ident, $key_name:ident, [TRACKED_NO_CRATE_HASH], + ($early_dcx:ident, $collected_options:ident, $unstable_opts:ident)) => {{}}; + ($opt:ident, $group_name:ident, $key_name:ident, [SUBSTRUCT], + ($early_dcx:ident, $collected_options:ident, $unstable_opts:ident)) => {{}}; } impl CodegenOptions { @@ -2475,8 +2461,7 @@ pub mod parse { } options! { - CodegenOptions, CodegenOptionsMetadata, CodegenOptionsKey, - CG_OPTIONS, cgopts, "C", Some("T"), codegen, + CodegenOptions, CodegenOptionsKey, CG_OPTIONS, cgopts, "C", Some("T"), codegen, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs @@ -2625,7 +2610,7 @@ options! { } options! { - UnstableOptions, UnstableOptionsMetadata, UnstableOptionsKey, Z_OPTIONS, dbopts, "Z", None, unstable, + UnstableOptions, UnstableOptionsKey, Z_OPTIONS, dbopts, "Z", None, unstable, // If you add a new option, please update: // - compiler/rustc_interface/src/tests.rs From 8d0c5093e2eeaf2f85cfe3626b534dad3f1257ab Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 19/29] sess: `-Tsanitizer{,-cfi-normalize-integers}` (again) --- compiler/rustc_interface/src/tests.rs | 3 +- compiler/rustc_session/src/options.rs | 121 +++++++----------- compiler/rustc_session/src/session.rs | 16 +-- compiler/rustc_target/src/spec/mod.rs | 2 +- tests/codegen-llvm/naked-asan.rs | 2 +- .../address-sanitizer-globals-tracking.rs | 2 +- .../sanitizer/sanitize-off-inlining.rs | 4 +- .../sanitizer/sanitize-off-kasan-asan.rs | 4 +- tests/codegen-llvm/sanitizer/sanitize-off.rs | 2 +- .../sanitizer/sanitizer-recover.rs | 4 +- tests/ui/sanitizer/cfg.rs | 4 +- tests/ui/sanitizer/crt-static.rs | 2 +- tests/ui/sanitizer/incompatible.rs | 4 +- tests/ui/sanitizer/incompatible.stderr | 2 +- tests/ui/sanitizer/unsupported-target.rs | 2 +- ...izer-kcfi-normalize-ints.wrong_flag.stderr | 4 +- ...kcfi-normalize-ints.wrong_sanitizer.stderr | 6 +- .../sanitizers-good-for-inconsistency.rs | 4 +- 18 files changed, 79 insertions(+), 109 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index b98e3f464865a..d0df8dfdcf771 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -659,6 +659,8 @@ fn test_codegen_options_tracking_hash() { tracked!(profile_use, Some(PathBuf::from("abc"))); tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); + tracked!(sanitizer, SanitizerSet::CFI); + tracked!(sanitizer_cfi_normalize_integers, Some(true)); tracked!(split_debuginfo, Some(SplitDebuginfo::Packed)); tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0)); tracked!(target_cpu, Some(String::from("abc"))); @@ -865,7 +867,6 @@ fn test_unstable_options_tracking_hash() { tracked!(profiler_runtime, "abc".to_string()); tracked!(relax_elf_relocations, Some(true)); tracked!(remap_cwd_prefix, Some(PathBuf::from("abc"))); - tracked!(sanitizer, SanitizerSet::ADDRESS); tracked!(sanitizer_cfi_canonical_jump_tables, None); tracked!(sanitizer_cfi_generalize_pointers, Some(true)); tracked!(sanitizer_dataflow_abilist, vec![String::from("/rustc/abc")]); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index fb59ca5d0f262..17fe8ac2d09ab 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -912,10 +912,8 @@ mod desc { pub(crate) const parse_patchable_function_entry: &str = "a comma separated list of (prefix_nops,total_nops,section_name), (prefix_nops,total_nops), or (total_nops). Where prefix_nops <= total_nops where 0 < total_nops <= 255 and prefix_nops <= total_nops"; pub(crate) const parse_opt_panic_strategy: &str = parse_panic_strategy; pub(crate) const parse_relro_level: &str = "one of: `full`, `partial`, or `off`"; - pub(crate) const parse_sanitizers_all: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; - pub(crate) const parse_sanitizers_target: &str = "comma separated list of sanitizers: `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; - pub(crate) const parse_sanitizers_other: &str = - "comma separated list of sanitizers: `address`, or `leak`"; + pub(crate) const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, or `leak` with `-C`; and `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime' with `-T`"; + pub(crate) const parse_sanitizers_unfiltered: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `leak`, `kcfi`, `kernel-address`, `kernel-hwaddress`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`, or 'realtime'"; pub(crate) const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2"; pub(crate) const parse_cfguard: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`"; @@ -1413,59 +1411,52 @@ pub mod parse { true } - enum SanitizerFilter { - All, - TargetModifiers, - NonTargetModifiers, + pub(crate) fn parse_sanitizers( + slot: &mut SanitizerSet, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { + parse_sanitizers_with_filter(slot, v, is_target_modifier, true) + } + + pub(crate) fn parse_sanitizers_unfiltered( + slot: &mut SanitizerSet, + v: Option<&str>, + is_target_modifier: bool, + ) -> bool { + parse_sanitizers_with_filter(slot, v, is_target_modifier, false) } - fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>, filter: SanitizerFilter) -> bool { + fn parse_sanitizers_with_filter( + slot: &mut SanitizerSet, + v: Option<&str>, + is_target_modifier: bool, + with_filter: bool, + ) -> bool { if let Some(v) = v { for s in v.split(',') { - match filter { - SanitizerFilter::All => { - *slot |= match s { - "address" => SanitizerSet::ADDRESS, - "cfi" => SanitizerSet::CFI, - "dataflow" => SanitizerSet::DATAFLOW, - "kcfi" => SanitizerSet::KCFI, - "kernel-address" => SanitizerSet::KERNELADDRESS, - "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, - "leak" => SanitizerSet::LEAK, - "memory" => SanitizerSet::MEMORY, - "memtag" => SanitizerSet::MEMTAG, - "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, - "thread" => SanitizerSet::THREAD, - "hwaddress" => SanitizerSet::HWADDRESS, - "safestack" => SanitizerSet::SAFESTACK, - "realtime" => SanitizerSet::REALTIME, - _ => return false, - } + *slot |= match s { + "cfi" if !with_filter || is_target_modifier => SanitizerSet::CFI, + "dataflow" if !with_filter || is_target_modifier => SanitizerSet::DATAFLOW, + "kcfi" if !with_filter || is_target_modifier => SanitizerSet::KCFI, + "kernel-address" if !with_filter || is_target_modifier => { + SanitizerSet::KERNELADDRESS } - SanitizerFilter::TargetModifiers => { - *slot |= match s { - "cfi" => SanitizerSet::CFI, - "dataflow" => SanitizerSet::DATAFLOW, - "kcfi" => SanitizerSet::KCFI, - "kernel-address" => SanitizerSet::KERNELADDRESS, - "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, - "memory" => SanitizerSet::MEMORY, - "memtag" => SanitizerSet::MEMTAG, - "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, - "thread" => SanitizerSet::THREAD, - "hwaddress" => SanitizerSet::HWADDRESS, - "safestack" => SanitizerSet::SAFESTACK, - "realtime" => SanitizerSet::REALTIME, - _ => return false, - } + "kernel-hwaddress" if !with_filter || is_target_modifier => { + SanitizerSet::KERNELHWADDRESS } - SanitizerFilter::NonTargetModifiers => { - *slot |= match s { - "address" => SanitizerSet::ADDRESS, - "leak" => SanitizerSet::LEAK, - _ => return false, - } + "memory" if !with_filter || is_target_modifier => SanitizerSet::MEMORY, + "memtag" if !with_filter || is_target_modifier => SanitizerSet::MEMTAG, + "shadow-call-stack" if !with_filter || is_target_modifier => { + SanitizerSet::SHADOWCALLSTACK } + "thread" if !with_filter || is_target_modifier => SanitizerSet::THREAD, + "hwaddress" if !with_filter || is_target_modifier => SanitizerSet::HWADDRESS, + "safestack" if !with_filter || is_target_modifier => SanitizerSet::SAFESTACK, + "realtime" if !with_filter || is_target_modifier => SanitizerSet::REALTIME, + "address" if !with_filter || !is_target_modifier => SanitizerSet::ADDRESS, + "leak" if !with_filter || !is_target_modifier => SanitizerSet::LEAK, + _ => return false, } } true @@ -1474,26 +1465,6 @@ pub mod parse { } } - pub(crate) fn parse_sanitizers_all(slot: &mut SanitizerSet, v: Option<&str>, _: bool) -> bool { - parse_sanitizers(slot, v, SanitizerFilter::All) - } - - pub(crate) fn parse_sanitizers_target( - slot: &mut SanitizerSet, - v: Option<&str>, - _: bool, - ) -> bool { - parse_sanitizers(slot, v, SanitizerFilter::TargetModifiers) - } - - pub(crate) fn parse_sanitizers_other( - slot: &mut SanitizerSet, - v: Option<&str>, - _: bool, - ) -> bool { - parse_sanitizers(slot, v, SanitizerFilter::NonTargetModifiers) - } - pub(crate) fn parse_sanitizer_memory_track_origins( slot: &mut usize, v: Option<&str>, @@ -2580,6 +2551,11 @@ options! { "output remarks for these optimization passes (space separated, or \"all\")"), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes (default: no)"), + #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] + sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], + "use a sanitizer"), + sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "enable normalizing integer types (default: no)"), save_temps: bool = (false, parse_bool, [UNTRACKED], "save all temporary output files during compilation (default: no)"), soft_float: () = ((), parse_ignore, [UNTRACKED], @@ -3028,9 +3004,6 @@ written to standard error output)"), retpoline_external_thunk: bool = (false, parse_bool, [TRACKED], "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ target features (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] - sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_other, [TRACKED], - "use a sanitizer"), sanitizer_cfi_canonical_jump_tables: Option = (Some(true), parse_opt_bool, [TRACKED], "enable canonical jump tables (default: yes)"), sanitizer_cfi_generalize_pointers: Option = (None, parse_opt_bool, [TRACKED], @@ -3045,7 +3018,7 @@ written to standard error output)"), "enable KCFI arity indicator (default: no)"), sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED], "enable origins tracking in MemorySanitizer"), - sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_all, [TRACKED], + sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers_unfiltered, [TRACKED], "enable recovery for selected sanitizers"), saturating_float_casts: Option = (None, parse_opt_bool, [TRACKED], "make float->int casts UB-free: numbers outside the integer type's range are clipped to \ diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index e3c3f23ddee67..507bc7b162f76 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -616,7 +616,7 @@ impl Session { } pub fn is_sanitizer_cfi_normalize_integers_enabled(&self) -> bool { - self.opts.target_opts.sanitizer_cfi_normalize_integers == Some(true) + self.opts.cg.sanitizer_cfi_normalize_integers == Some(true) } pub fn is_sanitizer_kcfi_arity_enabled(&self) -> bool { @@ -905,7 +905,7 @@ impl Session { let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly) || self.opts.output_types.contains_key(&OutputType::Bitcode) // AddressSanitizer and MemorySanitizer use alloca name when reporting an issue. - || self.opts.unstable_opts.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY); + || self.opts.cg.sanitizer.intersects(SanitizerSet::ADDRESS | SanitizerSet::MEMORY); !more_names } } @@ -1154,9 +1154,7 @@ impl Session { } pub fn sanitizers(&self) -> SanitizerSet { - return self.opts.target_opts.sanitizer - | self.opts.unstable_opts.sanitizer - | self.target.options.default_sanitizers; + return self.opts.cg.sanitizer | self.target.options.default_sanitizers; } pub fn pointer_authentication(&self) -> bool { @@ -1460,11 +1458,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - let user_enabled_sanitizers = - sess.opts.target_opts.sanitizer | sess.opts.unstable_opts.sanitizer; // Sanitizers can only be used on platforms that we know have working sanitizer codegen. let supported_sanitizers = sess.target.options.supported_sanitizers; - let mut unsupported_sanitizers = user_enabled_sanitizers - supported_sanitizers; + let mut unsupported_sanitizers = sess.opts.cg.sanitizer - supported_sanitizers; // Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled // we should allow Shadow Call Stack sanitizer. if sess.opts.target_opts.fixed_x18 && sess.target.arch == Arch::AArch64 { @@ -1485,7 +1481,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } // Cannot mix and match mutually-exclusive sanitizers. - if let Some((first, second)) = user_enabled_sanitizers.mutually_exclusive() { + if let Some((first, second)) = sess.opts.cg.sanitizer.mutually_exclusive() { sess.dcx().emit_err(diagnostics::CannotMixAndMatchSanitizers { first_prefix: first.prefix().expect("no prefix"), first: first.to_string(), @@ -1495,7 +1491,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } // Cannot enable crt-static with sanitizers on Linux - if sess.crt_static(None) && !user_enabled_sanitizers.is_empty() && !sess.target.is_like_msvc { + if sess.crt_static(None) && !sess.opts.cg.sanitizer.is_empty() && !sess.target.is_like_msvc { sess.dcx().emit_err(diagnostics::CannotEnableCrtStaticLinux); } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 235d06546db89..3b15766cd2271 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1231,7 +1231,7 @@ impl SanitizerSet { pub fn prefix(self) -> Option<&'static str> { Some(match self { - SanitizerSet::ADDRESS | SanitizerSet::LEAK => "Z", + SanitizerSet::ADDRESS | SanitizerSet::LEAK => "C", SanitizerSet::CFI | SanitizerSet::DATAFLOW | SanitizerSet::KCFI diff --git a/tests/codegen-llvm/naked-asan.rs b/tests/codegen-llvm/naked-asan.rs index 9dbbee47f75d7..0bc04bab6d48b 100644 --- a/tests/codegen-llvm/naked-asan.rs +++ b/tests/codegen-llvm/naked-asan.rs @@ -1,6 +1,6 @@ //@ add-minicore //@ needs-llvm-components: x86 -//@ compile-flags: --target x86_64-unknown-linux-gnu -Zsanitizer=address -Ctarget-feature=-crt-static +//@ compile-flags: --target x86_64-unknown-linux-gnu -Csanitizer=address -Ctarget-feature=-crt-static -Zunstable-options // Make sure we do not request sanitizers for naked functions. diff --git a/tests/codegen-llvm/sanitizer/address-sanitizer-globals-tracking.rs b/tests/codegen-llvm/sanitizer/address-sanitizer-globals-tracking.rs index ada525b6c8033..7597b79bb745d 100644 --- a/tests/codegen-llvm/sanitizer/address-sanitizer-globals-tracking.rs +++ b/tests/codegen-llvm/sanitizer/address-sanitizer-globals-tracking.rs @@ -19,7 +19,7 @@ //@ only-linux // //@ revisions:ASAN ASAN-FAT-LTO -//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Csanitizer=address -Ctarget-feature=-crt-static -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options // [ASAN] no extra compile-flags //@[ASAN-FAT-LTO] compile-flags: -Cprefer-dynamic=false -Clto=fat diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-inlining.rs b/tests/codegen-llvm/sanitizer/sanitize-off-inlining.rs index 0f43e6b8393dd..f7dbf03ee29d7 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-inlining.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-inlining.rs @@ -5,8 +5,8 @@ //@ revisions: ASAN LSAN //@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer //@ compile-flags: -Copt-level=3 -Zmir-opt-level=4 -Ctarget-feature=-crt-static -//@[ASAN] compile-flags: -Zsanitizer=address -//@[LSAN] compile-flags: -Zsanitizer=leak +//@[ASAN] compile-flags: -Csanitizer=address -Zunstable-options +//@[LSAN] compile-flags: -Csanitizer=leak -Zunstable-options #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs b/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs index 873412a8d1894..dcf198fe45856 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off-kasan-asan.rs @@ -2,8 +2,8 @@ // the address sanitizer. // //@ needs-sanitizer-address -//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 -//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer +//@ compile-flags: -Csanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 +//@ compile-flags: -C unsafe-allow-abi-mismatch=sanitizer -Zunstable-options #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/sanitize-off.rs b/tests/codegen-llvm/sanitizer/sanitize-off.rs index ac7c49322c6d8..fabe2c4707842 100644 --- a/tests/codegen-llvm/sanitizer/sanitize-off.rs +++ b/tests/codegen-llvm/sanitizer/sanitize-off.rs @@ -2,7 +2,7 @@ // selectively disable sanitizer instrumentation. // //@ needs-sanitizer-address -//@ compile-flags: -Zsanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 +//@ compile-flags: -Csanitizer=address -Ctarget-feature=-crt-static -Copt-level=0 -Zunstable-options #![crate_type = "lib"] #![feature(sanitize)] diff --git a/tests/codegen-llvm/sanitizer/sanitizer-recover.rs b/tests/codegen-llvm/sanitizer/sanitizer-recover.rs index 951a7934bab33..0e8d52f849c9e 100644 --- a/tests/codegen-llvm/sanitizer/sanitizer-recover.rs +++ b/tests/codegen-llvm/sanitizer/sanitizer-recover.rs @@ -7,8 +7,8 @@ //@ no-prefer-dynamic //@ compile-flags: -Cunsafe-allow-abi-mismatch=sanitizer //@ compile-flags: -Ctarget-feature=-crt-static -//@[ASAN] compile-flags: -Zsanitizer=address -Copt-level=0 -//@[ASAN-RECOVER] compile-flags: -Zsanitizer=address -Zsanitizer-recover=address -Copt-level=0 +//@[ASAN] compile-flags: -Csanitizer=address -Copt-level=0 -Zunstable-options +//@[ASAN-RECOVER] compile-flags: -Csanitizer=address -Zsanitizer-recover=address -Copt-level=0 //@[MSAN] compile-flags: -Tsanitizer=memory -Zunstable-options //@[MSAN-RECOVER] compile-flags: -Tsanitizer=memory -Zsanitizer-recover=memory //@[MSAN-RECOVER] compile-flags: -Zunstable-options diff --git a/tests/ui/sanitizer/cfg.rs b/tests/ui/sanitizer/cfg.rs index d135acb8c23a8..f562c7afc5df9 100644 --- a/tests/ui/sanitizer/cfg.rs +++ b/tests/ui/sanitizer/cfg.rs @@ -6,7 +6,7 @@ //@ revisions: address cfi kcfi leak memory thread //@compile-flags: -Ctarget-feature=-crt-static //@[address]needs-sanitizer-address -//@[address]compile-flags: -Zsanitizer=address +//@[address]compile-flags: -Csanitizer=address -Zunstable-options //@[cfi]needs-sanitizer-cfi //@[cfi]compile-flags: -Tsanitizer=cfi -Zunstable-options //@[cfi]compile-flags: -Clto -Ccodegen-units=1 @@ -14,7 +14,7 @@ //@[kcfi]compile-flags: -Tsanitizer=kcfi --target x86_64-unknown-none -Zunstable-options //@[kcfi]compile-flags: -C panic=abort //@[leak]needs-sanitizer-leak -//@[leak]compile-flags: -Zsanitizer=leak +//@[leak]compile-flags: -Csanitizer=leak -Zunstable-options //@[memory]needs-sanitizer-memory //@[memory]compile-flags: -Tsanitizer=memory -Zunstable-options //@[thread]needs-sanitizer-thread diff --git a/tests/ui/sanitizer/crt-static.rs b/tests/ui/sanitizer/crt-static.rs index b8bdf28351c3d..e58b9d199b6de 100644 --- a/tests/ui/sanitizer/crt-static.rs +++ b/tests/ui/sanitizer/crt-static.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Z sanitizer=address -C target-feature=+crt-static --target x86_64-unknown-linux-gnu +//@ compile-flags: -C sanitizer=address -C target-feature=+crt-static --target x86_64-unknown-linux-gnu -Z unstable-options //@ needs-llvm-components: x86 #![feature(no_core)] diff --git a/tests/ui/sanitizer/incompatible.rs b/tests/ui/sanitizer/incompatible.rs index b4ce0b7a8756e..55f3a0a08de0f 100644 --- a/tests/ui/sanitizer/incompatible.rs +++ b/tests/ui/sanitizer/incompatible.rs @@ -1,8 +1,8 @@ -//@ compile-flags: -Zsanitizer=address -Tsanitizer=memory --target x86_64-unknown-linux-gnu -Zunstable-options +//@ compile-flags: -Csanitizer=address -Tsanitizer=memory --target x86_64-unknown-linux-gnu -Zunstable-options //@ needs-llvm-components: x86 #![feature(no_core)] #![no_core] #![no_main] -//~? ERROR `-Zsanitizer=address` is incompatible with `-Tsanitizer=memory` +//~? ERROR `-Csanitizer=address` is incompatible with `-Tsanitizer=memory` diff --git a/tests/ui/sanitizer/incompatible.stderr b/tests/ui/sanitizer/incompatible.stderr index 7fded4645b1cc..68b31b0624a9f 100644 --- a/tests/ui/sanitizer/incompatible.stderr +++ b/tests/ui/sanitizer/incompatible.stderr @@ -1,4 +1,4 @@ -error: `-Zsanitizer=address` is incompatible with `-Tsanitizer=memory` +error: `-Csanitizer=address` is incompatible with `-Tsanitizer=memory` error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/unsupported-target.rs b/tests/ui/sanitizer/unsupported-target.rs index 19a99c314387c..092e31f666b96 100644 --- a/tests/ui/sanitizer/unsupported-target.rs +++ b/tests/ui/sanitizer/unsupported-target.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Zsanitizer=leak --target i686-unknown-linux-gnu +//@ compile-flags: -Csanitizer=leak --target i686-unknown-linux-gnu -Zunstable-options //@ needs-llvm-components: x86 //@ ignore-backends: gcc diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr index 4e95d3431164c..e6283714c2cc4 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_flag.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Tsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers=true` in dependency `kcfi_normalize_ints` - = help: set `-Tsanitizer-cfi-normalize-integers=true` in this crate or unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` + = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers` in dependency `kcfi_normalize_ints` + = help: set `-Tsanitizer-cfi-normalize-integers` in this crate, unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints`, or use `-Csanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer-cfi-normalize-integers` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr index c768298c0294e..e76e43266b4ea 100644 --- a/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr +++ b/tests/ui/target_modifiers/sanitizer-kcfi-normalize-ints.wrong_sanitizer.stderr @@ -6,7 +6,7 @@ LL | #![feature(no_core)] | = help: the `-Tsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset `-Tsanitizer` in this crate is incompatible with `-Tsanitizer=kcfi` in dependency `kcfi_normalize_ints` - = help: set `-Tsanitizer=kcfi` in this crate or unset `-Tsanitizer` in `kcfi_normalize_ints` + = help: set `-Tsanitizer=kcfi` in this crate, unset `-Tsanitizer` in `kcfi_normalize_ints`, or use `-Csanitizer` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer` to silence this error error: mixing `-Tsanitizer-cfi-normalize-integers` will cause an ABI mismatch in crate `sanitizer_kcfi_normalize_ints` @@ -16,8 +16,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Tsanitizer-cfi-normalize-integers` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers=true` in dependency `kcfi_normalize_ints` - = help: set `-Tsanitizer-cfi-normalize-integers=true` in this crate or unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` + = note: unset `-Tsanitizer-cfi-normalize-integers` in this crate is incompatible with `-Tsanitizer-cfi-normalize-integers` in dependency `kcfi_normalize_ints` + = help: set `-Tsanitizer-cfi-normalize-integers` in this crate, unset `-Tsanitizer-cfi-normalize-integers` in `kcfi_normalize_ints`, or use `-Csanitizer-cfi-normalize-integers` in `kcfi_normalize_ints` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer-cfi-normalize-integers` to silence this error error: aborting due to 2 previous errors diff --git a/tests/ui/target_modifiers/sanitizers-good-for-inconsistency.rs b/tests/ui/target_modifiers/sanitizers-good-for-inconsistency.rs index abda7be9e4057..2edfc52cd1232 100644 --- a/tests/ui/target_modifiers/sanitizers-good-for-inconsistency.rs +++ b/tests/ui/target_modifiers/sanitizers-good-for-inconsistency.rs @@ -8,8 +8,8 @@ //@ aux-build:no-sanitizers.rs //@ compile-flags: -Cpanic=abort -C target-feature=-crt-static -//@[wrong_address_san] compile-flags: -Zsanitizer=address -//@[wrong_leak_san] compile-flags: -Zsanitizer=leak +//@[wrong_address_san] compile-flags: -Csanitizer=address -Zunstable-options +//@[wrong_leak_san] compile-flags: -Csanitizer=leak -Zunstable-options //@ check-pass #![feature(no_core)] From 10344c511d61987199e00931071292a0d9a7a7b0 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 20/29] sess: `-Tbranch-protection` (again) --- compiler/rustc_interface/src/tests.rs | 8 ++++++++ compiler/rustc_session/src/options.rs | 3 +++ compiler/rustc_session/src/session.rs | 4 ++-- .../branch-protection-missing-pac-ret.BADFLAGS.stderr | 2 +- .../branch-protection-missing-pac-ret.BADFLAGSPC.stderr | 2 +- .../invalid/branch-protection-missing-pac-ret.rs | 4 ++-- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index d0df8dfdcf771..15033a2dbedd0 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -630,6 +630,14 @@ fn test_codegen_options_tracking_hash() { // Make sure that changing a [TRACKED] option changes the hash. // tidy-alphabetical-start + tracked!( + branch_protection, + Some(BranchProtection { + bti: true, + pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }), + gcs: true, + }) + ); tracked!(code_model, Some(CodeModel::Large)); tracked!(collapse_macro_debuginfo, CollapseMacroDebuginfo::Yes); tracked!(control_flow_guard, CFGuard::Checks); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 17fe8ac2d09ab..a81b0334b4bc9 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2442,6 +2442,9 @@ options! { ar: () = ((), parse_ignore, [UNTRACKED], "this option has been removed", removed: Err), + #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] + branch_protection: Option = (None, parse_branch_protection, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "set options for branch target identification and pointer authentication on AArch64"), #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")] code_model: Option = (None, parse_code_model, [TRACKED], "choose the code model to use (`rustc --print code-models` for details)"), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 507bc7b162f76..326d9c9f9c929 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -976,7 +976,7 @@ impl Session { /// Accessing the session's unstable `branch_protection` option fields directly is linted /// against. pub fn branch_protection(&self) -> Option { - let mut bp = self.opts.target_opts.branch_protection; + let mut bp = self.opts.cg.branch_protection; if let Some(bp) = bp.as_mut() { // Windows on Arm only supports PAC Key B for return address signing, as shown in @@ -1581,7 +1581,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if sess.opts.target_opts.branch_protection.is_some() && sess.target.arch != Arch::AArch64 { + if sess.opts.cg.branch_protection.is_some() && sess.target.arch != Arch::AArch64 { sess.dcx().emit_err(diagnostics::BranchProtectionRequiresAArch64); } diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr index fec7ced984393..4ed88fcceb538 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGS.stderr @@ -1,2 +1,2 @@ -error: incorrect value `leaf` for target option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected +error: incorrect value `leaf` for codegen option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr index 0a9157835aa91..13752a951c28b 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.BADFLAGSPC.stderr @@ -1,2 +1,2 @@ -error: incorrect value `pc` for target option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected +error: incorrect value `pc` for codegen option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected diff --git a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs index 791c66b9efcf0..481d536cf32ab 100644 --- a/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs +++ b/tests/ui/compile-flags/invalid/branch-protection-missing-pac-ret.rs @@ -23,6 +23,6 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -//[BADFLAGS]~? ERROR incorrect value `leaf` for target option `branch-protection` -//[BADFLAGSPC]~? ERROR incorrect value `pc` for target option `branch-protection` +//[BADFLAGS]~? ERROR incorrect value `leaf` for codegen option `branch-protection` +//[BADFLAGSPC]~? ERROR incorrect value `pc` for codegen option `branch-protection` //[BADTARGET]~? ERROR `-Tbranch-protection` is only supported on aarch64 From 4fe8be038d5b099e83f88c0c13b86b54b43af635 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 21/29] sess: `-Tregparm` (again) --- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_session/src/options.rs | 4 ++++ compiler/rustc_session/src/session.rs | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 11dbe30ed8a10..9efc084dee9ff 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -532,8 +532,8 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> { impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - regparm: self.tcx.sess.opts.target_opts.regparm, reg_struct_return: self.tcx.sess.opts.target_opts.reg_struct_return, + regparm: self.tcx.sess.opts.cg.regparm, } } } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 91553dc742793..f3a6c55ee1e69 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -396,7 +396,7 @@ pub(crate) unsafe fn create_module<'ll>( } } - if let Some(regparm_count) = sess.opts.target_opts.regparm { + if let Some(regparm_count) = sess.opts.cg.regparm { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Error, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 15033a2dbedd0..8caa8d6d0ed7c 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -665,6 +665,7 @@ fn test_codegen_options_tracking_hash() { tracked!(prefer_dynamic, true); tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); tracked!(profile_use, Some(PathBuf::from("abc"))); + tracked!(regparm, Some(3)); tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); tracked!(sanitizer, SanitizerSet::CFI); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index c164b6c764c7b..1d73a708c1065 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -624,8 +624,8 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> { impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - regparm: self.sess.opts.target_opts.regparm, reg_struct_return: self.sess.opts.target_opts.reg_struct_return, + regparm: self.sess.opts.cg.regparm, } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a81b0334b4bc9..5bd17e4d6cd4f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2544,6 +2544,10 @@ options! { "compile the program with profiling instrumentation"), profile_use: Option = (None, parse_opt_pathbuf, [TRACKED], "use the given `.profdata` file for profile-guided optimization"), + regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ + in registers EAX, EDX, and ECX instead of on the stack for\ + \"C\", \"cdecl\", and \"stdcall\" fn."), #[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")] relocation_model: Option = (None, parse_relocation_model, [TRACKED], "control generation of position-independent code (PIC) \ diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 326d9c9f9c929..f5f4e4b7b84dc 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1649,7 +1649,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if let Some(regparm) = sess.opts.target_opts.regparm { + if let Some(regparm) = sess.opts.cg.regparm { if regparm > 3 { sess.dcx().emit_err(diagnostics::UnsupportedRegparm { regparm }); } From f294e26d1837a0af235fb8e489e6b90da5bd6ad2 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 22/29] sess: `-Tindirect-branch-cs-prefix` (again) --- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_session/src/options.rs | 2 ++ compiler/rustc_session/src/session.rs | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index f3a6c55ee1e69..6fbf4dbf45411 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -514,7 +514,7 @@ pub(crate) unsafe fn create_module<'ll>( ); } - if sess.opts.target_opts.indirect_branch_cs_prefix { + if sess.opts.cg.indirect_branch_cs_prefix { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Override, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 8caa8d6d0ed7c..0633e78283c2a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -647,6 +647,7 @@ fn test_codegen_options_tracking_hash() { tracked!(embed_bitcode, false); tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); + tracked!(indirect_branch_cs_prefix, true); tracked!(instrument_coverage, InstrumentCoverage::Yes); tracked!(jump_tables, false); tracked!(link_dead_code, Some(true)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 5bd17e4d6cd4f..ff58c42f1eb7f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2479,6 +2479,8 @@ options! { help: bool = (false, parse_no_value, [UNTRACKED], "Print codegen options"), incremental: Option = (None, parse_opt_string, [UNTRACKED], "enable incremental compilation"), + indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), inline_threshold: () = ((), parse_ignore, [UNTRACKED], "this option has been removed \ (consider using `-Cllvm-args=--inline-threshold=...`)", diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index f5f4e4b7b84dc..99060c2dab42d 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1643,7 +1643,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if sess.opts.target_opts.indirect_branch_cs_prefix { + if sess.opts.cg.indirect_branch_cs_prefix { if !matches!(sess.target.arch, Arch::X86 | Arch::X86_64) { sess.dcx().emit_err(diagnostics::IndirectBranchCsPrefixRequiresX86OrX8664); } From 853e59be07570803c1701d35784eae73967e13d4 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 23/29] sess: `-Tfixed-x18` (again) --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_session/src/options.rs | 2 ++ compiler/rustc_session/src/session.rs | 2 +- .../incompatible_fixedx18.error_generated.stderr | 4 ++-- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index c47af74871a9e..33021ddb95429 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -638,7 +638,7 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec) { target_features::sanitizer_features_by_flags(sess, features); // -Zfixed-x18 - if sess.opts.target_opts.fixed_x18 { + if sess.opts.cg.fixed_x18 { if sess.target.arch != Arch::AArch64 { sess.dcx() .emit_fatal(diagnostics::FixedX18InvalidArch { arch: sess.target.arch.desc() }); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 0633e78283c2a..e26c67ad390c6 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -645,6 +645,7 @@ fn test_codegen_options_tracking_hash() { tracked!(debuginfo, DebugInfo::Limited); tracked!(dwarf_version, Some(5)); tracked!(embed_bitcode, false); + tracked!(fixed_x18, true); tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); tracked!(indirect_branch_cs_prefix, true); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index ff58c42f1eb7f..0f47e8bb97f90 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2471,6 +2471,8 @@ options! { "emit bitcode in rlibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED] { TARGET_MODIFIER: Never }, "extra data to put in each output filename"), + fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "make the x18 register reserved on AArch64 (default: no)"), force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED], "force use of the frame pointers"), #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")] diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 99060c2dab42d..93b0b595e3310 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1463,7 +1463,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { let mut unsupported_sanitizers = sess.opts.cg.sanitizer - supported_sanitizers; // Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled // we should allow Shadow Call Stack sanitizer. - if sess.opts.target_opts.fixed_x18 && sess.target.arch == Arch::AArch64 { + if sess.opts.cg.fixed_x18 && sess.target.arch == Arch::AArch64 { unsupported_sanitizers -= SanitizerSet::SHADOWCALLSTACK; } match unsupported_sanitizers.into_iter().count() { diff --git a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr index d5e6155b70e96..fca40eb50def4 100644 --- a/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr +++ b/tests/ui/target_modifiers/incompatible_fixedx18.error_generated.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Tfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Tfixed-x18` in this crate is incompatible with `-Tfixed-x18=true` in dependency `fixed_x18` - = help: set `-Tfixed-x18=true` in this crate or unset `-Tfixed-x18` in `fixed_x18` + = note: unset `-Tfixed-x18` in this crate is incompatible with `-Tfixed-x18` in dependency `fixed_x18` + = help: set `-Tfixed-x18` in this crate, unset `-Tfixed-x18` in `fixed_x18`, or use `-Cfixed-x18` in `fixed_x18` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=fixed-x18` to silence this error error: aborting due to 1 previous error From 72392b7cf2541d55a57d7de0fb2d47e8866a35d8 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 24/29] sess: `-Tretpoline{,-external-thunk}` (again) --- compiler/rustc_codegen_ssa/src/target_features.rs | 6 +++--- compiler/rustc_interface/src/tests.rs | 2 ++ compiler/rustc_session/src/config.rs | 4 ++-- compiler/rustc_session/src/options.rs | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 6ce27b025402a..67ec70629f5db 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -491,15 +491,15 @@ pub fn flag_to_backend_features<'a>( pub fn retpoline_features_by_flags(sess: &Session, features: &mut Vec) { // -Tretpoline without -Tretpoline-external-thunk enables // retpoline-indirect-branches and retpoline-indirect-calls target features - let target_opts = &sess.opts.target_opts; - if target_opts.retpoline && !target_opts.retpoline_external_thunk { + let cg = &sess.opts.cg; + if cg.retpoline && !cg.retpoline_external_thunk { features.push("+retpoline-indirect-branches".into()); features.push("+retpoline-indirect-calls".into()); } // -Tretpoline-external-thunk (maybe, with -Tretpoline too) enables // retpoline-external-thunk, retpoline-indirect-branches and // retpoline-indirect-calls target features - if target_opts.retpoline_external_thunk { + if cg.retpoline_external_thunk { features.push("+retpoline-external-thunk".into()); features.push("+retpoline-indirect-branches".into()); features.push("+retpoline-indirect-calls".into()); diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e26c67ad390c6..e4acb0c9b6b64 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -670,6 +670,8 @@ fn test_codegen_options_tracking_hash() { tracked!(regparm, Some(3)); tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); + tracked!(retpoline, true); + tracked!(retpoline_external_thunk, true); tracked!(sanitizer, SanitizerSet::CFI); tracked!(sanitizer_cfi_normalize_integers, Some(true)); tracked!(split_debuginfo, Some(SplitDebuginfo::Packed)); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 5ea67cb4c6875..004bc9f4163df 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2941,8 +2941,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let prints = print_request::collect_print_requests(early_dcx, &mut cg, &unstable_opts, matches); // -Zretpoline-external-thunk also requires -Zretpoline - if target_opts.retpoline_external_thunk { - target_opts.retpoline = true; + if cg.retpoline_external_thunk { + cg.retpoline = true; } let cg = cg; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 0f47e8bb97f90..643c13dbffa58 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2560,6 +2560,11 @@ options! { "choose which RELRO level to use"), remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED], "output remarks for these optimization passes (space separated, or \"all\")"), + retpoline: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), + retpoline_external_thunk: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ + target features (default: no)"), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes (default: no)"), #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] From 3777b1706d03b6f7bf83b5334f5db0a69bc8d099 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Jul 2026 16:28:59 +0000 Subject: [PATCH 25/29] sess: `-Treg-struct-return` (again) --- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_session/src/options.rs | 2 ++ compiler/rustc_session/src/session.rs | 2 +- .../ui/target_modifiers/defaults_check.error.stderr | 6 +++--- .../defaults_check.error_explicit.stderr | 13 +++++++++++++ tests/ui/target_modifiers/defaults_check.rs | 8 ++++---- .../ui/target_modifiers/no_value_bool.error.stderr | 4 ++-- .../no_value_bool.error_explicit.stderr | 4 ++-- 10 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 tests/ui/target_modifiers/defaults_check.error_explicit.stderr diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 9efc084dee9ff..c390e95d34c0b 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -532,8 +532,8 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> { impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - reg_struct_return: self.tcx.sess.opts.target_opts.reg_struct_return, regparm: self.tcx.sess.opts.cg.regparm, + reg_struct_return: self.tcx.sess.opts.cg.reg_struct_return, } } } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e4acb0c9b6b64..bd77dc8e27dbb 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -667,6 +667,7 @@ fn test_codegen_options_tracking_hash() { tracked!(prefer_dynamic, true); tracked!(profile_generate, SwitchWithOptPath::Enabled(None)); tracked!(profile_use, Some(PathBuf::from("abc"))); + tracked!(reg_struct_return, true); tracked!(regparm, Some(3)); tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 1d73a708c1065..84429383d0684 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -624,8 +624,8 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> { impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> { fn x86_abi_opt(&self) -> X86Abi { X86Abi { - reg_struct_return: self.sess.opts.target_opts.reg_struct_return, regparm: self.sess.opts.cg.regparm, + reg_struct_return: self.sess.opts.cg.reg_struct_return, } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 643c13dbffa58..3746df32aff0b 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2548,6 +2548,8 @@ options! { "compile the program with profiling instrumentation"), profile_use: Option = (None, parse_opt_pathbuf, [TRACKED], "use the given `.profdata` file for profile-guided optimization"), + reg_struct_return: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "On x86-32 targets, it overrides the default ABI to return small structs in registers."), regparm: Option = (None, parse_opt_number, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "On x86-32 targets, setting this to N causes the compiler to pass N arguments \ in registers EAX, EDX, and ECX instead of on the stack for\ diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 93b0b595e3310..33d5ee907072c 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1657,7 +1657,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { sess.dcx().emit_err(diagnostics::UnsupportedRegparmArch); } } - if sess.opts.target_opts.reg_struct_return { + if sess.opts.cg.reg_struct_return { if sess.target.arch != Arch::X86 { sess.dcx().emit_err(diagnostics::UnsupportedRegStructReturnArch); } diff --git a/tests/ui/target_modifiers/defaults_check.error.stderr b/tests/ui/target_modifiers/defaults_check.error.stderr index 922dc78da70aa..d8779c40c817f 100644 --- a/tests/ui/target_modifiers/defaults_check.error.stderr +++ b/tests/ui/target_modifiers/defaults_check.error.stderr @@ -1,12 +1,12 @@ error: mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` - --> $DIR/defaults_check.rs:16:1 + --> $DIR/defaults_check.rs:15:1 | LL | #![feature(no_core)] | ^ | = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Treg-struct-return=true` in this crate is incompatible with `-Treg-struct-return=false` in dependency `default_reg_struct_return` - = help: set `-Treg-struct-return=false` in this crate or `-Treg-struct-return=true` in `default_reg_struct_return` + = note: unset `-Treg-struct-return` in `default_reg_struct_return` is incompatible with `-Treg-struct-return` in this crate + = help: set `-Treg-struct-return` in `default_reg_struct_return`, unset `-Treg-struct-return` in this crate, or use `-Creg-struct-return` in this crate instead = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/defaults_check.error_explicit.stderr b/tests/ui/target_modifiers/defaults_check.error_explicit.stderr new file mode 100644 index 0000000000000..d8779c40c817f --- /dev/null +++ b/tests/ui/target_modifiers/defaults_check.error_explicit.stderr @@ -0,0 +1,13 @@ +error: mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` + --> $DIR/defaults_check.rs:15:1 + | +LL | #![feature(no_core)] + | ^ + | + = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely + = note: unset `-Treg-struct-return` in `default_reg_struct_return` is incompatible with `-Treg-struct-return` in this crate + = help: set `-Treg-struct-return` in `default_reg_struct_return`, unset `-Treg-struct-return` in this crate, or use `-Creg-struct-return` in this crate instead + = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error + +error: aborting due to 1 previous error + diff --git a/tests/ui/target_modifiers/defaults_check.rs b/tests/ui/target_modifiers/defaults_check.rs index b901030c0c693..3a0433220e80f 100644 --- a/tests/ui/target_modifiers/defaults_check.rs +++ b/tests/ui/target_modifiers/defaults_check.rs @@ -5,16 +5,16 @@ //@ compile-flags: --target i686-unknown-linux-gnu -Cpanic=abort -Zunstable-options //@ needs-llvm-components: x86 -//@ revisions: ok ok_explicit error +//@ revisions: ok error_explicit error // [ok] no extra compile-flags -//@[ok_explicit] compile-flags: -Treg-struct-return=false +//@[error_explicit] compile-flags: -Treg-struct-return=false //@[error] compile-flags: -Treg-struct-return=true //@[ok] check-pass -//@[ok_explicit] check-pass //@ ignore-backends: gcc #![feature(no_core)] -//[error]~^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` +//[error_explicit]~^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` +//[error]~^^ ERROR mixing `-Treg-struct-return` will cause an ABI mismatch in crate `defaults_check` #![crate_type = "rlib"] #![no_core] diff --git a/tests/ui/target_modifiers/no_value_bool.error.stderr b/tests/ui/target_modifiers/no_value_bool.error.stderr index f27619ed9399c..130c02523122f 100644 --- a/tests/ui/target_modifiers/no_value_bool.error.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Treg-struct-return` in this crate is incompatible with `-Treg-struct-return=true` in dependency `enabled_reg_struct_return` - = help: set `-Treg-struct-return=true` in this crate or unset `-Treg-struct-return` in `enabled_reg_struct_return` + = note: unset `-Treg-struct-return` in this crate is incompatible with `-Treg-struct-return` in dependency `enabled_reg_struct_return` + = help: set `-Treg-struct-return` in this crate, unset `-Treg-struct-return` in `enabled_reg_struct_return`, or use `-Creg-struct-return` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error diff --git a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr index e0520f4106fe0..3de9c3a2530a6 100644 --- a/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr +++ b/tests/ui/target_modifiers/no_value_bool.error_explicit.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Treg-struct-return` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: `-Treg-struct-return=false` in this crate is incompatible with `-Treg-struct-return=true` in dependency `enabled_reg_struct_return` - = help: set `-Treg-struct-return=true` in this crate or `-Treg-struct-return=false` in `enabled_reg_struct_return` + = note: `-Treg-struct-return` in this crate is incompatible with `-Treg-struct-return` in dependency `enabled_reg_struct_return` + = help: set `-Treg-struct-return` in this crate or `-Treg-struct-return` in `enabled_reg_struct_return` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=reg-struct-return` to silence this error error: aborting due to 1 previous error From 6a92a97dd523827c34906deb979a277fc0b24878 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 29 Jul 2026 15:18:05 +0000 Subject: [PATCH 26/29] sess: `-Ttarget-cpu` (again) --- compiler/rustc_codegen_cranelift/src/lib.rs | 4 +- compiler/rustc_codegen_llvm/src/llvm_util.rs | 6 +-- .../rustc_codegen_ssa/src/back/metadata.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 6 +-- .../rustc_codegen_ssa/src/target_features.rs | 2 +- compiler/rustc_session/src/diagnostics.rs | 4 -- compiler/rustc_session/src/options.rs | 6 +-- compiler/rustc_session/src/session.rs | 42 +++++++++---------- tests/run-make/target-cpu-precedence/lib.rs | 2 +- ...arget_cpu_default.implicit_mismatch.stderr | 4 +- 10 files changed, 36 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index 8b092681e0c2c..8b0ca770ec067 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -206,7 +206,7 @@ impl CodegenBackend for CraneliftCodegenBackend { fn target_cpu(&self, sess: &Session) -> String { // FIXME handle `-Ctarget-cpu=native` - match sess.target_cpu() { + match sess.opts.cg.target_cpu { Some(ref name) => name, None => sess.target.cpu.as_ref(), } @@ -339,7 +339,7 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { let flags = settings::Flags::new(flags_builder); - let isa_builder = match sess.target_cpu().as_deref() { + let isa_builder = match sess.opts.cg.target_cpu.as_deref() { Some(NATIVE_CPU) => cranelift_native::builder_with_options(true).unwrap(), Some(value) => { let mut builder = diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 33021ddb95429..6e02b1d7796df 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -624,7 +624,7 @@ fn handle_native(cpu_name: &str) -> &str { } pub(crate) fn target_cpu(sess: &Session) -> &str { - let cpu_name = sess.target_cpu().unwrap_or_else(|| &sess.target.cpu); + let cpu_name = sess.opts.cg.target_cpu.as_deref().unwrap_or_else(|| &sess.target.cpu); handle_native(cpu_name) } @@ -676,8 +676,8 @@ pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec let mut features = vec![]; // -Ctarget-cpu=native - match sess.target_cpu() { - Some(s) if s == NATIVE_CPU => { + match sess.opts.cg.target_cpu { + Some(ref s) if s == NATIVE_CPU => { // We have already figured out the actual CPU name with `LLVMRustGetHostCPUName` and set // that for LLVM, so the features implied by that CPU name will be available everywhere. // However, that is not sufficient: e.g. `skylake` alone is not sufficient to tell if diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 6502052ec02d5..a43bf72b6a27d 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -368,7 +368,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 { Architecture::Avr => { // Resolve the ISA revision and set // the appropriate EF_AVR_ARCH flag. - if let Some(ref cpu) = sess.target_cpu() { + if let Some(ref cpu) = sess.opts.cg.target_cpu { ef_avr_arch(cpu) } else { sess.dcx().emit_fatal(diagnostics::CpuRequired) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index c25535d3d39a0..e8013fb867bc6 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -718,13 +718,13 @@ pub fn codegen_crate< backend: B, tcx: TyCtxt<'_>, ) -> OngoingCodegen { - if tcx.sess.target.need_explicit_cpu && tcx.sess.target_cpu().is_none() { + if tcx.sess.target.need_explicit_cpu && tcx.sess.opts.cg.target_cpu.is_none() { // The target has no default cpu, but none is set explicitly tcx.dcx().emit_fatal(diagnostics::CpuRequired); } - if let Some(target_cpu) = &tcx.sess.target_cpu() - && tcx.sess.target.unsupported_cpus.contains(&(*target_cpu).into()) + if let Some(target_cpu) = &tcx.sess.opts.cg.target_cpu + && tcx.sess.target.unsupported_cpus.contains(&target_cpu.into()) { // The target cpu is explicitly listed as an unsupported cpu tcx.dcx().emit_fatal(diagnostics::CpuUnsupported { target_cpu: target_cpu.to_string() }); diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 67ec70629f5db..01e3b3f337afe 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -433,7 +433,7 @@ pub fn target_spec_to_backend_features<'a>( // sm_70, sm_72 and sm_75 defaults to PTX ISA versions with major version 6, while sm_80 default to 7.0 if sess.target.arch == Arch::Nvptx64 && matches!( - sess.target_cpu().as_deref(), + sess.opts.cg.target_cpu.as_deref(), None | Some("sm_70") | Some("sm_72") | Some("sm_75") ) { diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 5e19b9fc05399..e301ccaf7e4d1 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -811,7 +811,3 @@ pub(crate) struct IncompatibleFlagsUnsetExternally { #[derive(Diagnostic)] #[diag("`target-cpu` must be set with `-Ttarget-cpu` for this target")] pub(crate) struct TargetCpuNeedsTargetModifierOpt; - -#[derive(Diagnostic)] -#[diag("`target-cpu` must be set with `-Ctarget-cpu` for this target")] -pub(crate) struct TargetCpuNeedsCodegenOpt; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3746df32aff0b..b0003b18bca0a 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -266,6 +266,7 @@ pub enum TargetModifierValue { Bool(bool), U32(u32), Usize(usize), + String(String), BranchProtection(BranchProtection), Sanitizers(SanitizerSet), } @@ -276,6 +277,7 @@ impl fmt::Display for TargetModifierValue { Self::Bool(_) => write!(f, ""), Self::U32(val) => write!(f, "={val}"), Self::Usize(val) => write!(f, "={val}"), + Self::String(val) => write!(f, "={val}"), Self::BranchProtection(val) => write!(f, "={val}"), Self::Sanitizers(val) => write!(f, "={val}"), } @@ -297,6 +299,7 @@ macro_rules! noop_target_modifier_ty { noop_target_modifier_ty!( // tidy-alphabetical-start SanitizerSet => Self::Sanitizers, + String => Self::String, bool => Self::Bool, u32 => Self::U32, usize => Self::Usize, @@ -378,7 +381,6 @@ unsupported_target_modifier_ty!( Option, Option, Option, - Option, Option, Option, Option, @@ -392,7 +394,6 @@ unsupported_target_modifier_ty!( ProcMacroExecutionStrategy, SplitDwarfKind, StackProtector, - String, Strip, SwitchWithOptPath, TerminalUrl, @@ -2588,7 +2589,6 @@ options! { symbol_mangling_version: Option = (None, parse_symbol_mangling_version, [TRACKED], "which mangling version to use for symbol names ('legacy', 'v0' (default), or 'hashed')"), - #[rustc_lint_opt_deny_field_access("use `Session::target_cpu` instead of this field")] target_cpu: Option = (None, parse_opt_string, [TRACKED], "select target processor (`rustc --print target-cpus` for details)"), target_feature: String = (String::new(), parse_target_feature, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 33d5ee907072c..955e0c946dea9 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -34,9 +34,10 @@ use rustc_target::spec::{ use crate::code_stats::CodeStats; pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use crate::config::{ - self, BranchProtection, Cfg, CheckCfg, CoverageLevel, CoverageOptions, CrateType, DebugInfo, - ErrorOutputType, FunctionReturn, Input, InstrumentCoverage, InstrumentMcount, NATIVE_CPU, - OptLevel, OutFileName, OutputType, PAuthKey, PointerAuthOption, SwitchWithOptPath, + self, BranchProtection, Cfg, CheckCfg, CodegenOptionsKey, CoverageLevel, CoverageOptions, + CrateType, DebugInfo, ErrorOutputType, FunctionReturn, Input, InstrumentCoverage, + InstrumentMcount, NATIVE_CPU, OptLevel, OutFileName, OutputType, PAuthKey, PointerAuthOption, + SwitchWithOptPath, }; use crate::filesearch::FileSearch; use crate::lint::LintId; @@ -585,20 +586,6 @@ impl Session { &self.opts.unstable_opts.coverage_options } - // JUSTIFICATION: defn of wrapper around `target_cpu` - #[allow(rustc::bad_opt_access)] - pub fn target_cpu(&self) -> Option<&str> { - // `opts.target_opts.target_cpu` can have a value set so that default values of `target-cpu` - // match across crates, but the rest of the compiler expects this function to only return - // a value if it was explicitly set - let target_value = if self.opts.metadata.target.target_cpu.is_set { - self.opts.target_opts.target_cpu.as_deref() - } else { - None - }; - target_value.or(self.opts.cg.target_cpu.as_deref()) - } - pub fn is_sanitizer_cfi_enabled(&self) -> bool { self.sanitizers().contains(SanitizerSet::CFI) } @@ -1277,8 +1264,13 @@ pub fn build_session( // default for the option be compatible with an explicitly set `-Ttarget-cpu`, but because the // `-Ttarget-cpu` default cannot be set in `options!` (it's target-specific, unsurprisingly), // the default needs to be written here so it is in cross-crate metadata. - if target.requires_consistent_cpu && !sopts.metadata.target.target_cpu.is_set { - sopts.target_opts.target_cpu = Some(target.cpu.to_string()); + let target_cpu_set = + sopts.collected_options.is_set.codegen.contains(&CodegenOptionsKey::target_cpu); + if target.requires_consistent_cpu && !target_cpu_set { + sopts.collected_options.target_modifiers.codegen.insert( + CodegenOptionsKey::target_cpu, + config::TargetModifierValue::String(target.cpu.to_string()), + ); } let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile @@ -1430,10 +1422,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) { }); } - if sess.target.requires_consistent_cpu && sess.opts.metadata.codegen.target_cpu.is_set { + let target_cpu_set = + sess.opts.collected_options.is_set.codegen.contains(&CodegenOptionsKey::target_cpu); + let target_cpu_set_as_modifier = sess + .opts + .collected_options + .target_modifiers + .codegen + .contains_key(&CodegenOptionsKey::target_cpu); + if sess.target.requires_consistent_cpu && target_cpu_set && !target_cpu_set_as_modifier { sess.dcx().emit_err(diagnostics::TargetCpuNeedsTargetModifierOpt); - } else if !sess.target.requires_consistent_cpu && sess.opts.metadata.target.target_cpu.is_set { - sess.dcx().emit_err(diagnostics::TargetCpuNeedsCodegenOpt); } // Make sure that any given profiling data actually exists so LLVM can't diff --git a/tests/run-make/target-cpu-precedence/lib.rs b/tests/run-make/target-cpu-precedence/lib.rs index d343e7762d53c..25588ef2282db 100644 --- a/tests/run-make/target-cpu-precedence/lib.rs +++ b/tests/run-make/target-cpu-precedence/lib.rs @@ -34,4 +34,4 @@ pub fn foo() { } // The value reconstructed from crate metadata must be identical. // CHECK-LABEL: =Target modifiers= -// CHECK-LABEL: -Ttarget-cpu=sm_80 ["sm_80"] +// CHECK-LABEL: -Ttarget-cpu=sm_80 diff --git a/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr b/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr index bf4ecb952a229..dcbf72801149a 100644 --- a/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr +++ b/tests/ui/target_modifiers/target_cpu_default.implicit_mismatch.stderr @@ -5,8 +5,8 @@ LL | #![feature(no_core)] | ^ | = help: the `-Ttarget-cpu` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely - = note: unset `-Ttarget-cpu` in this crate is incompatible with `-Ttarget-cpu=sm_80` in dependency `target_cpu_non_default` - = help: set `-Ttarget-cpu=sm_80` in this crate or unset `-Ttarget-cpu` in `target_cpu_non_default` + = note: `-Ttarget-cpu=sm_70` in this crate is incompatible with `-Ttarget-cpu=sm_80` in dependency `target_cpu_non_default` + = help: set `-Ttarget-cpu=sm_80` in this crate or `-Ttarget-cpu=sm_70` in `target_cpu_non_default` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=target-cpu` to silence this error error: aborting due to 1 previous error From c5264c3a8c22c62e5fd37672051ce8c8fb7c98d8 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 29 Jul 2026 15:18:05 +0000 Subject: [PATCH 27/29] sess: `-Tpointer-authentication` (again) --- compiler/rustc_session/src/options.rs | 29 +++++++++++++++++++ compiler/rustc_session/src/session.rs | 6 ++-- ...thentication_validation.all_unknown.stderr | 2 +- ...ter_authentication_validation.empty.stderr | 2 +- ...ter_authentication_validation.mixed.stderr | 2 +- ...nable_pointer_authentication_validation.rs | 8 ++--- ...uthentication_validation.unprefixed.stderr | 2 +- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index b0003b18bca0a..7cd0e576ccfab 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -269,6 +269,7 @@ pub enum TargetModifierValue { String(String), BranchProtection(BranchProtection), Sanitizers(SanitizerSet), + PointerAuthentication(Vec<(PointerAuthOption, bool)>), } impl fmt::Display for TargetModifierValue { @@ -280,6 +281,14 @@ impl fmt::Display for TargetModifierValue { Self::String(val) => write!(f, "={val}"), Self::BranchProtection(val) => write!(f, "={val}"), Self::Sanitizers(val) => write!(f, "={val}"), + Self::PointerAuthentication(vals) => { + let mut parts = Vec::new(); + for (opt, pos) in vals { + let polarity = if *pos { "+" } else { "-" }; + parts.push(format!("{polarity}{opt}")); + } + write!(f, "={}", parts.join(",")) + } } } } @@ -300,6 +309,7 @@ noop_target_modifier_ty!( // tidy-alphabetical-start SanitizerSet => Self::Sanitizers, String => Self::String, + Vec<(PointerAuthOption, bool)> => Self::PointerAuthentication, bool => Self::Bool, u32 => Self::U32, usize => Self::Usize, @@ -2542,6 +2552,25 @@ options! { "panic strategy to compile crate with"), passes: Vec = (Vec::new(), parse_list, [TRACKED], "a list of extra LLVM passes to run (space separated)"), + pointer_authentication: Vec<(PointerAuthOption, bool)> = ( + Vec::new(), + parse_pointer_authentication_list_with_polarity, + [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options: + `aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch + `auth-traps` - trap immediately on pointer authentication failure + `calls` - enable signing and authentication of all indirect calls + `elf-got` - enable authentication of pointers from GOT (ELF only) + `function-pointer-type-discrimination` - enable type discrimination on C function pointers + `indirect-gotos` - enable signing and authentication of indirect goto targets + `init-fini` - enable signing of function pointers in init/fini arrays + `init-fini-address-discrimination` - enable address discrimination in init/fini arrays + `intrinsics` - pointer authentication intrinsics + `return-addresses` - enable signing and authentication of return addresses + `typeinfo-vt-ptr-discrimination - incorporate type and address discrimination in authenticated vtable pointers for std::type_info + `vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers + `vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers + Example: `-Zpointer-authentication=+calls,-init-fini`."), prefer_dynamic: bool = (false, parse_bool, [TRACKED], "prefer dynamic linking to static linking (default: no)"), profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 955e0c946dea9..14ca26d828b20 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1334,7 +1334,7 @@ pub fn build_session( let timings = TimingSectionHandler::new(sopts.json_timings); let pointer_auth_config: Option = - PointerAuthConfig::from_raw(&sopts.target_opts.pointer_authentication, &target); + PointerAuthConfig::from_raw(&sopts.cg.pointer_authentication, &target); let sess = Session { target, @@ -1414,9 +1414,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { ); } - if sess.target.cfg_abi != CfgAbi::Pauthtest - && !sess.opts.target_opts.pointer_authentication.is_empty() - { + if sess.target.cfg_abi != CfgAbi::Pauthtest && !sess.opts.cg.pointer_authentication.is_empty() { sess.dcx().emit_warn(diagnostics::PointerAuthenticationNotSupportedForTarget { target_triple: &sess.opts.target_triple, }); diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr index 793fedf401add..18fba4735a7fb 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.all_unknown.stderr @@ -1,2 +1,2 @@ -error: incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `+I,+do,-not,-exist` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr index 6e508b25967ae..bd27df70ee216 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.empty.stderr @@ -1,2 +1,2 @@ -error: incorrect value `` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr index 1e889bb97610b..f2fb32e62da5d 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.mixed.stderr @@ -1,2 +1,2 @@ -error: incorrect value `+elf-got,-imaginary` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `+elf-got,-imaginary` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs index 700294765b875..9a21332ddd06a 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs @@ -19,7 +19,7 @@ #![no_main] #![no_core] -//[empty]~? ERROR incorrect value `` for target option `pointer-authentication` -//[unprefixed]~? ERROR incorrect value `auth-traps` for target option `pointer-authentication` -//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication` -//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for target option `pointer-authentication` +//[empty]~? ERROR incorrect value `` for codegen option `pointer-authentication` +//[unprefixed]~? ERROR incorrect value `auth-traps` for codegen option `pointer-authentication` +//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for codegen option `pointer-authentication` +//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for codegen option `pointer-authentication` diff --git a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr index 00ad442d2823d..8aec0241f834b 100644 --- a/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr +++ b/tests/ui/pointer_authentication/enable_pointer_authentication_validation.unprefixed.stderr @@ -1,2 +1,2 @@ -error: incorrect value `auth-traps` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected +error: incorrect value `auth-traps` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+` or `-`, where `` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected From 99f6a3fa44c4e42c0e499bd627e6eba708a9951c Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 12 Aug 2026 13:39:40 +0000 Subject: [PATCH 28/29] sess: `-Tllvm-target-feature` (again) --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 2 +- compiler/rustc_session/src/options.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 6e02b1d7796df..843bb4d7d1e2f 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -748,7 +748,7 @@ pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec // `-Tllvm-target-features`, all the way at the end to overwrite everything. // Should be picked up by `cfg` (e.g. if someone enables AVX this way). - for feature in sess.opts.target_opts.llvm_target_feature.split(',') { + for feature in sess.opts.cg.llvm_target_feature.split(',') { if feature.is_empty() { continue; } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 7cd0e576ccfab..93a7dad57b57b 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2526,6 +2526,10 @@ options! { "generate build artifacts that are compatible with linker-based LTO"), llvm_args: Vec = (Vec::new(), parse_list, [TRACKED], "a list of arguments to pass to LLVM (space separated)"), + llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, + "enable/disable LLVM-level target features. \ + This feature is unsafe and can cause ABI issues and compiler crashes, \ + because LLVM does not support all target feature combinations."), #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")] lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED], "perform LLVM link-time optimizations"), From 9901111ee29393891750e3582c76046bc97a3f16 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 12 Aug 2026 13:48:57 +0000 Subject: [PATCH 29/29] sess: existing flags cannot be used with `-T` This makes these refactorings a no-op. Specific flags can be revisited in a later PR. --- compiler/rustc_session/src/options.rs | 104 +++++++++++++------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 93a7dad57b57b..02a65cf8e91e8 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2450,111 +2450,111 @@ options! { // - src/doc/rustc/src/codegen-options/index.md // tidy-alphabetical-start - ar: () = ((), parse_ignore, [UNTRACKED], + ar: () = ((), parse_ignore, [UNTRACKED] { TARGET_MODIFIER: Never }, "this option has been removed", removed: Err), #[rustc_lint_opt_deny_field_access("use `Session::branch_protection` instead of this field")] branch_protection: Option = (None, parse_branch_protection, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "set options for branch target identification and pointer authentication on AArch64"), #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")] - code_model: Option = (None, parse_code_model, [TRACKED], + code_model: Option = (None, parse_code_model, [TRACKED] { TARGET_MODIFIER: Never }, "choose the code model to use (`rustc --print code-models` for details)"), - codegen_units: Option = (None, parse_opt_number, [UNTRACKED], + codegen_units: Option = (None, parse_opt_number, [UNTRACKED] { TARGET_MODIFIER: Never }, "divide crate into N units to optimize in parallel"), collapse_macro_debuginfo: CollapseMacroDebuginfo = (CollapseMacroDebuginfo::Unspecified, - parse_collapse_macro_debuginfo, [TRACKED], + parse_collapse_macro_debuginfo, [TRACKED] { TARGET_MODIFIER: Never }, "set option to collapse debuginfo for macros"), - control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED] { MITIGATION: ControlFlowGuard }, + control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED] { MITIGATION: ControlFlowGuard } { TARGET_MODIFIER: Never }, "use Windows Control Flow Guard (default: no)"), - debug_assertions: Option = (None, parse_opt_bool, [TRACKED], + debug_assertions: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: Never }, "explicitly enable the `cfg(debug_assertions)` directive"), - debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED], + debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED] { TARGET_MODIFIER: Never }, "debug info emission level (0-2, none, line-directives-only, \ line-tables-only, limited, or full; default: 0)"), - default_linker_libraries: bool = (false, parse_bool, [UNTRACKED], + default_linker_libraries: bool = (false, parse_bool, [UNTRACKED] { TARGET_MODIFIER: Never }, "allow the linker to link its default libraries (default: no)"), - dlltool: Option = (None, parse_opt_pathbuf, [UNTRACKED], + dlltool: Option = (None, parse_opt_pathbuf, [UNTRACKED] { TARGET_MODIFIER: Never }, "import library generation tool (ignored except when targeting windows-gnu)"), #[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")] - dwarf_version: Option = (None, parse_opt_number, [TRACKED], + dwarf_version: Option = (None, parse_opt_number, [TRACKED] { TARGET_MODIFIER: Never }, "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"), - embed_bitcode: bool = (true, parse_bool, [TRACKED], + embed_bitcode: bool = (true, parse_bool, [TRACKED] { TARGET_MODIFIER: Never }, "emit bitcode in rlibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED] { TARGET_MODIFIER: Never }, "extra data to put in each output filename"), fixed_x18: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "make the x18 register reserved on AArch64 (default: no)"), - force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED], + force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED] { TARGET_MODIFIER: Never }, "force use of the frame pointers"), #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")] - force_unwind_tables: Option = (None, parse_opt_bool, [TRACKED], + force_unwind_tables: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: Never }, "force use of unwind tables"), - help: bool = (false, parse_no_value, [UNTRACKED], "Print codegen options"), - incremental: Option = (None, parse_opt_string, [UNTRACKED], + help: bool = (false, parse_no_value, [UNTRACKED] { TARGET_MODIFIER: Never }, "Print codegen options"), + incremental: Option = (None, parse_opt_string, [UNTRACKED] { TARGET_MODIFIER: Never }, "enable incremental compilation"), indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"), - inline_threshold: () = ((), parse_ignore, [UNTRACKED], + inline_threshold: () = ((), parse_ignore, [UNTRACKED] { TARGET_MODIFIER: Never }, "this option has been removed \ (consider using `-Cllvm-args=--inline-threshold=...`)", removed: Err), #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")] - instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED], + instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED] { TARGET_MODIFIER: Never }, "instrument the generated code to support LLVM source-based code coverage reports \ (note, the compiler build config must include `profiler = true`); \ implies `-C symbol-mangling-version=v0`"), - jump_tables: bool = (true, parse_bool, [TRACKED], + jump_tables: bool = (true, parse_bool, [TRACKED] { TARGET_MODIFIER: Never }, "allow jump table and lookup table generation from switch case lowering (default: yes)"), - link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED], + link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED] { TARGET_MODIFIER: Never }, "a single extra argument to append to the linker invocation (can be used several times)"), - link_args: Vec = (Vec::new(), parse_list, [UNTRACKED], + link_args: Vec = (Vec::new(), parse_list, [UNTRACKED] { TARGET_MODIFIER: Never }, "extra arguments to append to the linker invocation (space separated)"), #[rustc_lint_opt_deny_field_access("use `Session::link_dead_code` instead of this field")] - link_dead_code: Option = (None, parse_opt_bool, [TRACKED], + link_dead_code: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: Never }, "try to generate and link dead code (default: no)"), - link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED], + link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED] { TARGET_MODIFIER: Never }, "control whether to link Rust provided C objects/libraries or rely \ on a C toolchain or linker installed in the system"), - linker: Option = (None, parse_opt_pathbuf, [UNTRACKED], + linker: Option = (None, parse_opt_pathbuf, [UNTRACKED] { TARGET_MODIFIER: Never }, "system linker to link outputs with"), - linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED], + linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED] { TARGET_MODIFIER: Never }, "a comma-separated list of linker features to enable (+) or disable (-): `lld`"), - linker_flavor: Option = (None, parse_linker_flavor, [UNTRACKED], + linker_flavor: Option = (None, parse_linker_flavor, [UNTRACKED] { TARGET_MODIFIER: Never }, "linker flavor"), linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled, - parse_linker_plugin_lto, [TRACKED], + parse_linker_plugin_lto, [TRACKED] { TARGET_MODIFIER: Never }, "generate build artifacts that are compatible with linker-based LTO"), - llvm_args: Vec = (Vec::new(), parse_list, [TRACKED], + llvm_args: Vec = (Vec::new(), parse_list, [TRACKED] { TARGET_MODIFIER: Never }, "a list of arguments to pass to LLVM (space separated)"), llvm_target_feature: String = (String::new(), parse_target_feature, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "enable/disable LLVM-level target features. \ This feature is unsafe and can cause ABI issues and compiler crashes, \ because LLVM does not support all target feature combinations."), #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")] - lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED], + lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED] { TARGET_MODIFIER: Never }, "perform LLVM link-time optimizations"), - metadata: Vec = (Vec::new(), parse_list, [TRACKED], + metadata: Vec = (Vec::new(), parse_list, [TRACKED] { TARGET_MODIFIER: Never }, "metadata to mangle symbol names with"), - no_prepopulate_passes: bool = (false, parse_no_value, [TRACKED], + no_prepopulate_passes: bool = (false, parse_no_value, [TRACKED] { TARGET_MODIFIER: Never }, "give an empty list of passes to the pass manager"), - no_redzone: Option = (None, parse_opt_bool, [TRACKED], + no_redzone: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: Never }, "disable the use of the redzone"), - no_stack_check: () = ((), parse_ignore, [UNTRACKED], + no_stack_check: () = ((), parse_ignore, [UNTRACKED] { TARGET_MODIFIER: Never }, "this option has been removed", removed: Err), - no_vectorize_loops: bool = (false, parse_no_value, [TRACKED], + no_vectorize_loops: bool = (false, parse_no_value, [TRACKED] { TARGET_MODIFIER: Never }, "disable loop vectorization optimization passes"), - no_vectorize_slp: bool = (false, parse_no_value, [TRACKED], + no_vectorize_slp: bool = (false, parse_no_value, [TRACKED] { TARGET_MODIFIER: Never }, "disable LLVM's SLP vectorization pass"), - opt_level: String = ("0".to_string(), parse_string, [TRACKED], + opt_level: String = ("0".to_string(), parse_string, [TRACKED] { TARGET_MODIFIER: Never }, "optimization level (0-3, s, or z; default: 0)"), #[rustc_lint_opt_deny_field_access("use `Session::overflow_checks` instead of this field")] - overflow_checks: Option = (None, parse_opt_bool, [TRACKED], + overflow_checks: Option = (None, parse_opt_bool, [TRACKED] { TARGET_MODIFIER: Never }, "use overflow checks for integer arithmetic"), #[rustc_lint_opt_deny_field_access("use `Session::panic_strategy` instead of this field")] - panic: Option = (None, parse_opt_panic_strategy, [TRACKED], + panic: Option = (None, parse_opt_panic_strategy, [TRACKED] { TARGET_MODIFIER: Never }, "panic strategy to compile crate with"), - passes: Vec = (Vec::new(), parse_list, [TRACKED], + passes: Vec = (Vec::new(), parse_list, [TRACKED] { TARGET_MODIFIER: Never }, "a list of extra LLVM passes to run (space separated)"), pointer_authentication: Vec<(PointerAuthOption, bool)> = ( Vec::new(), @@ -2575,12 +2575,12 @@ options! { `vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers `vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers Example: `-Zpointer-authentication=+calls,-init-fini`."), - prefer_dynamic: bool = (false, parse_bool, [TRACKED], + prefer_dynamic: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: Never }, "prefer dynamic linking to static linking (default: no)"), profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled, - parse_switch_with_opt_path, [TRACKED], + parse_switch_with_opt_path, [TRACKED] { TARGET_MODIFIER: Never }, "compile the program with profiling instrumentation"), - profile_use: Option = (None, parse_opt_pathbuf, [TRACKED], + profile_use: Option = (None, parse_opt_pathbuf, [TRACKED] { TARGET_MODIFIER: Never }, "use the given `.profdata` file for profile-guided optimization"), reg_struct_return: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "On x86-32 targets, it overrides the default ABI to return small structs in registers."), @@ -2589,45 +2589,45 @@ options! { in registers EAX, EDX, and ECX instead of on the stack for\ \"C\", \"cdecl\", and \"stdcall\" fn."), #[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")] - relocation_model: Option = (None, parse_relocation_model, [TRACKED], + relocation_model: Option = (None, parse_relocation_model, [TRACKED] { TARGET_MODIFIER: Never }, "control generation of position-independent code (PIC) \ (`rustc --print relocation-models` for details)"), - relro_level: Option = (None, parse_relro_level, [TRACKED], + relro_level: Option = (None, parse_relro_level, [TRACKED] { TARGET_MODIFIER: Never }, "choose which RELRO level to use"), - remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED], + remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED] { TARGET_MODIFIER: Never }, "output remarks for these optimization passes (space separated, or \"all\")"), retpoline: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), retpoline_external_thunk: bool = (false, parse_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "enables retpoline-external-thunk, retpoline-indirect-branches and retpoline-indirect-calls \ target features (default: no)"), - rpath: bool = (false, parse_bool, [UNTRACKED], + rpath: bool = (false, parse_bool, [UNTRACKED] { TARGET_MODIFIER: Never }, "set rpath values in libs/exes (default: no)"), #[rustc_lint_opt_deny_field_access("use `Session::sanitizers()` instead of this field")] sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], "use a sanitizer"), sanitizer_cfi_normalize_integers: Option = (None, parse_opt_bool, [TRACKED_UNSTABLE] { TARGET_MODIFIER: Only }, "enable normalizing integer types (default: no)"), - save_temps: bool = (false, parse_bool, [UNTRACKED], + save_temps: bool = (false, parse_bool, [UNTRACKED] { TARGET_MODIFIER: Never }, "save all temporary output files during compilation (default: no)"), - soft_float: () = ((), parse_ignore, [UNTRACKED], + soft_float: () = ((), parse_ignore, [UNTRACKED] { TARGET_MODIFIER: Never }, "this option has been removed \ (use a corresponding *eabi target instead)", removed: Err), #[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")] - split_debuginfo: Option = (None, parse_split_debuginfo, [TRACKED], + split_debuginfo: Option = (None, parse_split_debuginfo, [TRACKED] { TARGET_MODIFIER: Never }, "how to handle split-debuginfo, a platform-specific option"), - strip: Strip = (Strip::None, parse_strip, [UNTRACKED], + strip: Strip = (Strip::None, parse_strip, [UNTRACKED] { TARGET_MODIFIER: Never }, "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"), symbol_mangling_version: Option = (None, - parse_symbol_mangling_version, [TRACKED], + parse_symbol_mangling_version, [TRACKED] { TARGET_MODIFIER: Never }, "which mangling version to use for symbol names ('legacy', 'v0' (default), or 'hashed')"), target_cpu: Option = (None, parse_opt_string, [TRACKED], "select target processor (`rustc --print target-cpus` for details)"), - target_feature: String = (String::new(), parse_target_feature, [TRACKED], + target_feature: String = (String::new(), parse_target_feature, [TRACKED] { TARGET_MODIFIER: Never }, "target specific attributes. (`rustc --print target-features` for details). \ This feature is unsafe."), - unsafe_allow_abi_mismatch: Vec = (Vec::new(), parse_comma_list, [UNTRACKED], + unsafe_allow_abi_mismatch: Vec = (Vec::new(), parse_comma_list, [UNTRACKED] { TARGET_MODIFIER: Never }, "Allow incompatible target modifiers in dependency crates (comma separated list)"), // tidy-alphabetical-end