Skip to content

Commit 45ddafa

Browse files
committed
show a warning when -Csoft-float is used on a non-eabihf target
1 parent 9b82580 commit 45ddafa

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ codegen_llvm_sanitizer_memtag_requires_mte =
6060
codegen_llvm_serialize_module = failed to serialize module {$name}
6161
codegen_llvm_serialize_module_with_llvm_err = failed to serialize module {$name}: {$llvm_err}
6262
63+
codegen_llvm_soft_float_ignored =
64+
`-Csoft-float` is ignored on this target; it only has an effect on `*eabihf` targets
65+
6366
codegen_llvm_symbol_already_defined =
6467
symbol `{$symbol_name}` is already defined
6568

compiler/rustc_codegen_llvm/src/back/write.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::back::profiling::{
3535
selfprofile_after_pass_callback, selfprofile_before_pass_callback, LlvmSelfProfiler,
3636
};
3737
use crate::errors::{
38-
CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression,
38+
self, CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression,
3939
WithLlvmError, WriteBytecode,
4040
};
4141
use crate::llvm::diagnostic::OptimizationDiagnosticKind;
@@ -185,7 +185,17 @@ pub(crate) fn target_machine_factory(
185185
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
186186

187187
let (opt_level, _) = to_llvm_opt_settings(optlvl);
188-
let use_softfp = sess.opts.cg.soft_float;
188+
let use_softfp = if sess.target.arch == "arm" && sess.target.abi == "eabihf" {
189+
sess.opts.cg.soft_float
190+
} else {
191+
// All `use_softfp` does is the equivalent of `-mfloat-abi` in GCC/clang, which only exists on ARM targets.
192+
// We document this flag to only affect `*eabihf` targets, so let's show a warning for all other targets.
193+
if sess.opts.cg.soft_float {
194+
sess.dcx().emit_warn(errors::SoftFloatIgnored);
195+
}
196+
// Let's make sure LLVM doesn't suddenly start using this flag on more targets.
197+
false
198+
};
189199

190200
let ffunction_sections =
191201
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections);

compiler/rustc_codegen_llvm/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,7 @@ pub(crate) struct InvalidTargetFeaturePrefix<'a> {
231231
pub(crate) struct FixedX18InvalidArch<'a> {
232232
pub arch: &'a str,
233233
}
234+
235+
#[derive(Diagnostic)]
236+
#[diag(codegen_llvm_soft_float_ignored)]
237+
pub(crate) struct SoftFloatIgnored;

0 commit comments

Comments
 (0)