Skip to content

Commit fcc1604

Browse files
authored
Rollup merge of #152973 - RalfJung:soft-float, r=JonathanBrouwer
remove -Csoft-float This fixes #129893 by removing the offending flag. The flag has been added in pre-1.0 times (#9617) without much discussion, probably with the intent to mirror `-msoft-float` in C compilers. It never properly mirrored clang though because it only affected the LLVM float ABI setting, not the "soft-float" target feature (the clang flag sets both). It is also blatantly unsound because it affects how float arguments are passed, making it UB to invoke parts of the standard library. The flag got deprecated with Rust 1.83 (released November 2024), and in the year since then, nobody spoke up in #129893 to have it preserved. I think it is time to remove it. I can totally imagine us bringing back a similar flag, properly registered as a target modifier to preserve soundness, but that should come with a coherent design that works for more than one architecture (the flag only does anything on ARM). Blocked on approval of rust-lang/compiler-team#971. Fixes #154106
2 parents 734cca0 + e72674e commit fcc1604

6 files changed

Lines changed: 38 additions & 50 deletions

File tree

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use rustc_middle::ty::TyCtxt;
2323
use rustc_session::Session;
2424
use rustc_session::config::{self, Lto, OutputType, Passes, SplitDwarfKind, SwitchWithOptPath};
2525
use rustc_span::{BytePos, InnerSpan, Pos, RemapPathScopeComponents, SpanData, SyntaxContext, sym};
26-
use rustc_target::spec::{
27-
Arch, CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel,
28-
};
26+
use rustc_target::spec::{CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
2927
use tracing::{debug, trace};
3028

3129
use crate::back::lto::{Buffer, ModuleBuffer};
@@ -206,13 +204,7 @@ pub(crate) fn target_machine_factory(
206204
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
207205

208206
let (opt_level, _) = to_llvm_opt_settings(optlvl);
209-
let float_abi = if sess.target.arch == Arch::Arm && sess.opts.cg.soft_float {
210-
llvm::FloatAbi::Soft
211-
} else {
212-
// `validate_commandline_args_with_session_available` has already warned about this being
213-
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
214-
to_llvm_float_abi(sess.target.llvm_floatabi)
215-
};
207+
let float_abi = to_llvm_float_abi(sess.target.llvm_floatabi);
216208

217209
let ffunction_sections =
218210
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections);

compiler/rustc_interface/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ fn test_codegen_options_tracking_hash() {
637637
tracked!(profile_use, Some(PathBuf::from("abc")));
638638
tracked!(relocation_model, Some(RelocModel::Pic));
639639
tracked!(relro_level, Some(RelroLevel::Full));
640-
tracked!(soft_float, true);
641640
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
642641
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
643642
tracked!(target_cpu, Some(String::from("abc")));

compiler/rustc_session/src/errors.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,6 @@ pub(crate) struct FailedToCreateProfiler {
517517
pub(crate) err: String,
518518
}
519519

520-
#[derive(Diagnostic)]
521-
#[diag("`-Csoft-float` is ignored on this target; it only has an effect on *eabihf targets")]
522-
#[note("this may become a hard error in a future version of Rust")]
523-
pub(crate) struct SoftFloatIgnored;
524-
525-
#[derive(Diagnostic)]
526-
#[diag("`-Csoft-float` is unsound and deprecated; use a corresponding *eabi target instead")]
527-
#[note("it will be removed or ignored in a future version of Rust")]
528-
#[note("see issue #129893 <https://github.com/rust-lang/rust/issues/129893> for more information")]
529-
pub(crate) struct SoftFloatDeprecated;
530-
531520
#[derive(Diagnostic)]
532521
#[diag("unexpected `--cfg {$cfg}` flag")]
533522
#[note("config `{$cfg_name}` is only supposed to be controlled by `{$controlled_by}`")]

compiler/rustc_session/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
3+
#![feature(const_option_ops)]
4+
#![feature(const_trait_impl)]
35
#![feature(default_field_values)]
46
#![feature(iter_intersperse)]
57
#![feature(macro_derive)]

compiler/rustc_session/src/options.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ macro_rules! options {
611611
$parse:ident,
612612
[$dep_tracking_marker:ident $( $tmod:ident )?],
613613
$desc:expr
614-
$(, is_deprecated_and_do_nothing: $dnn:literal )?)
614+
$(, removed: $removed:ident )?)
615615
),* ,) =>
616616
(
617617
#[derive(Clone)]
@@ -667,7 +667,7 @@ macro_rules! options {
667667

668668
pub const $stat: OptionDescrs<$struct_name> =
669669
&[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
670-
type_desc: desc::$parse, desc: $desc, is_deprecated_and_do_nothing: false $( || $dnn )?,
670+
type_desc: desc::$parse, desc: $desc, removed: None $( .or(Some(RemovedOption::$removed)) )?,
671671
tmod: tmod_enum_opt!($struct_name, $tmod_enum_name, $opt, $($tmod),*) } ),* ];
672672

673673
mod $optmod {
@@ -705,14 +705,20 @@ macro_rules! redirect_field {
705705
type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
706706
type OptionDescrs<O> = &'static [OptionDesc<O>];
707707

708+
/// Indicates whether a removed option should warn or error.
709+
enum RemovedOption {
710+
Warn,
711+
Err,
712+
}
713+
708714
pub struct OptionDesc<O> {
709715
name: &'static str,
710716
setter: OptionSetter<O>,
711717
// description for return value/type from mod desc
712718
type_desc: &'static str,
713719
// description for option from options table
714720
desc: &'static str,
715-
is_deprecated_and_do_nothing: bool,
721+
removed: Option<RemovedOption>,
716722
tmod: Option<OptionsTargetModifiers>,
717723
}
718724

@@ -743,18 +749,18 @@ fn build_options<O: Default>(
743749

744750
let option_to_lookup = key.replace('-', "_");
745751
match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) {
746-
Some(OptionDesc {
747-
name: _,
748-
setter,
749-
type_desc,
750-
desc,
751-
is_deprecated_and_do_nothing,
752-
tmod,
753-
}) => {
754-
if *is_deprecated_and_do_nothing {
752+
Some(OptionDesc { name: _, setter, type_desc, desc, removed, tmod }) => {
753+
if let Some(removed) = removed {
755754
// deprecation works for prefixed options only
756755
assert!(!prefix.is_empty());
757-
early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"));
756+
match removed {
757+
RemovedOption::Warn => {
758+
early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"))
759+
}
760+
RemovedOption::Err => {
761+
early_dcx.early_fatal(format!("`-{prefix} {key}`: {desc}"))
762+
}
763+
}
758764
}
759765
if !setter(&mut op, value) {
760766
match value {
@@ -783,6 +789,7 @@ fn build_options<O: Default>(
783789

784790
#[allow(non_upper_case_globals)]
785791
mod desc {
792+
pub(crate) const parse_ignore: &str = "<ignored>"; // should not be user-visible
786793
pub(crate) const parse_no_value: &str = "no value";
787794
pub(crate) const parse_bool: &str =
788795
"one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`";
@@ -889,6 +896,12 @@ pub mod parse {
889896
pub(crate) use super::*;
890897
pub(crate) const MAX_THREADS_CAP: usize = 256;
891898

899+
/// Ignore the value. Used for removed options where we don't actually want to store
900+
/// anything in the session.
901+
pub(crate) fn parse_ignore(_slot: &mut (), _v: Option<&str>) -> bool {
902+
true
903+
}
904+
892905
/// This is for boolean options that don't take a value, and are true simply
893906
/// by existing on the command-line.
894907
///
@@ -2059,7 +2072,7 @@ options! {
20592072
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
20602073
ar: String = (String::new(), parse_string, [UNTRACKED],
20612074
"this option is deprecated and does nothing",
2062-
is_deprecated_and_do_nothing: true),
2075+
removed: Warn),
20632076
#[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
20642077
code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
20652078
"choose the code model to use (`rustc --print code-models` for details)"),
@@ -2098,7 +2111,7 @@ options! {
20982111
inline_threshold: Option<u32> = (None, parse_opt_number, [UNTRACKED],
20992112
"this option is deprecated and does nothing \
21002113
(consider using `-Cllvm-args=--inline-threshold=...`)",
2101-
is_deprecated_and_do_nothing: true),
2114+
removed: Warn),
21022115
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
21032116
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
21042117
"instrument the generated code to support LLVM source-based code coverage reports \
@@ -2139,7 +2152,7 @@ options! {
21392152
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
21402153
no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
21412154
"this option is deprecated and does nothing",
2142-
is_deprecated_and_do_nothing: true),
2155+
removed: Warn),
21432156
no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
21442157
"disable loop vectorization optimization passes"),
21452158
no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],
@@ -2173,8 +2186,11 @@ options! {
21732186
"set rpath values in libs/exes (default: no)"),
21742187
save_temps: bool = (false, parse_bool, [UNTRACKED],
21752188
"save all temporary output files during compilation (default: no)"),
2176-
soft_float: bool = (false, parse_bool, [TRACKED],
2177-
"deprecated option: use soft float ABI (*eabihf targets only) (default: no)"),
2189+
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
2190+
soft_float: () = ((), parse_ignore, [UNTRACKED],
2191+
"this option has been removed \
2192+
(use a corresponding *eabi target instead)",
2193+
removed: Err),
21782194
#[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")]
21792195
split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
21802196
"how to handle split-debuginfo, a platform-specific option"),

compiler/rustc_session/src/session.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,16 +1360,6 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13601360
}
13611361
}
13621362
}
1363-
1364-
if sess.opts.cg.soft_float {
1365-
if sess.target.arch == Arch::Arm {
1366-
sess.dcx().emit_warn(errors::SoftFloatDeprecated);
1367-
} else {
1368-
// All `use_softfp` does is the equivalent of `-mfloat-abi` in GCC/clang, which only exists on ARM targets.
1369-
// We document this flag to only affect `*eabihf` targets, so let's show a warning for all other targets.
1370-
sess.dcx().emit_warn(errors::SoftFloatIgnored);
1371-
}
1372-
}
13731363
}
13741364

13751365
/// Holds data on the current incremental compilation session, if there is one.

0 commit comments

Comments
 (0)