Skip to content

Commit 04a3187

Browse files
committed
Auto merge of rust-lang#130407 - matthiaskrgr:rollup-vo2gmf4, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#129897 (deprecate -Csoft-float because it is unsound (and not fixable)) - rust-lang#130339 (Add `core::panic::abort_unwind`) - rust-lang#130384 (compiler: Document AbiAndPrefAlign) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c2c9a9 + b3686b5 commit 04a3187

File tree

8 files changed

+78
-2
lines changed

8 files changed

+78
-2
lines changed

compiler/rustc_abi/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ impl Align {
781781
}
782782

783783
/// A pair of alignments, ABI-mandated and preferred.
784+
///
785+
/// The "preferred" alignment is an LLVM concept that is virtually meaningless to Rust code:
786+
/// it is not exposed semantically to programmers nor can they meaningfully affect it.
787+
/// The only concern for us is that preferred alignment must not be less than the mandated alignment
788+
/// and thus in practice the two values are almost always identical.
789+
///
790+
/// An example of a rare thing actually affected by preferred alignment is aligning of statics.
791+
/// It is of effectively no consequence for layout in structs and on the stack.
784792
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
785793
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
786794
pub struct AbiAndPrefAlign {

compiler/rustc_codegen_llvm/src/back/write.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,13 @@ 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+
// `validate_commandline_args_with_session_available` has already warned about this being ignored.
192+
// Let's make sure LLVM doesn't suddenly start using this flag on more targets.
193+
false
194+
};
189195

190196
let ffunction_sections =
191197
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections);

compiler/rustc_session/messages.ftl

+10
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ session_sanitizer_not_supported = {$us} sanitizer is not supported for this targ
107107
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target
108108
109109
session_skipping_const_checks = skipping const checks
110+
111+
session_soft_float_deprecated =
112+
`-Csoft-float` is unsound and deprecated; use a corresponding *eabi target instead
113+
.note = it will be removed or ignored in a future version of Rust
114+
session_soft_float_deprecated_issue = see issue #129893 <https://github.com/rust-lang/rust/issues/129893> for more information
115+
116+
session_soft_float_ignored =
117+
`-Csoft-float` is ignored on this target; it only has an effect on *eabihf targets
118+
.note = this may become a hard error in a future version of Rust
119+
110120
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform
111121
112122
session_split_lto_unit_requires_lto = `-Zsplit-lto-unit` requires `-Clto`, `-Clto=thin`, or `-Clinker-plugin-lto`

compiler/rustc_session/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,14 @@ pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel;
490490
pub(crate) struct FailedToCreateProfiler {
491491
pub(crate) err: String,
492492
}
493+
494+
#[derive(Diagnostic)]
495+
#[diag(session_soft_float_ignored)]
496+
#[note]
497+
pub(crate) struct SoftFloatIgnored;
498+
499+
#[derive(Diagnostic)]
500+
#[diag(session_soft_float_deprecated)]
501+
#[note]
502+
#[note(session_soft_float_deprecated_issue)]
503+
pub(crate) struct SoftFloatDeprecated;

compiler/rustc_session/src/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,7 @@ options! {
15151515
// - src/doc/rustc/src/codegen-options/index.md
15161516

15171517
// tidy-alphabetical-start
1518+
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
15181519
ar: String = (String::new(), parse_string, [UNTRACKED],
15191520
"this option is deprecated and does nothing"),
15201521
#[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
@@ -1547,6 +1548,7 @@ options! {
15471548
"force use of unwind tables"),
15481549
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
15491550
"enable incremental compilation"),
1551+
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
15501552
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
15511553
"this option is deprecated and does nothing \
15521554
(consider using `-Cllvm-args=--inline-threshold=...`)"),
@@ -1583,6 +1585,7 @@ options! {
15831585
"give an empty list of passes to the pass manager"),
15841586
no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
15851587
"disable the use of the redzone"),
1588+
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
15861589
no_stack_check: bool = (false, parse_no_flag, [UNTRACKED],
15871590
"this option is deprecated and does nothing"),
15881591
no_vectorize_loops: bool = (false, parse_no_flag, [TRACKED],
@@ -1619,7 +1622,7 @@ options! {
16191622
save_temps: bool = (false, parse_bool, [UNTRACKED],
16201623
"save all temporary output files during compilation (default: no)"),
16211624
soft_float: bool = (false, parse_bool, [TRACKED],
1622-
"use soft float ABI (*eabihf targets only) (default: no)"),
1625+
"deprecated option: use soft float ABI (*eabihf targets only) (default: no)"),
16231626
#[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")]
16241627
split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
16251628
"how to handle split-debuginfo, a platform-specific option"),

compiler/rustc_session/src/session.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13481348
}
13491349
}
13501350
}
1351+
1352+
if sess.opts.cg.soft_float {
1353+
if sess.target.arch == "arm" && sess.target.abi == "eabihf" {
1354+
sess.dcx().emit_warn(errors::SoftFloatDeprecated);
1355+
} else {
1356+
// All `use_softfp` does is the equivalent of `-mfloat-abi` in GCC/clang, which only exists on ARM targets.
1357+
// We document this flag to only affect `*eabihf` targets, so let's show a warning for all other targets.
1358+
sess.dcx().emit_warn(errors::SoftFloatIgnored);
1359+
}
1360+
}
13511361
}
13521362

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

library/core/src/panic.rs

+25
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ pub macro unreachable_2021 {
140140
),
141141
}
142142

143+
/// Invokes a closure, aborting if the closure unwinds.
144+
///
145+
/// When compiled with aborting panics, this function is effectively a no-op.
146+
/// With unwinding panics, an unwind results in another call into the panic
147+
/// hook followed by a process abort.
148+
///
149+
/// # Notes
150+
///
151+
/// Instead of using this function, code should attempt to support unwinding.
152+
/// Implementing [`Drop`] allows you to restore invariants uniformly in both
153+
/// return and unwind paths.
154+
///
155+
/// If an unwind can lead to logical issues but not soundness issues, you
156+
/// should allow the unwind. Opting out of [`UnwindSafe`] indicates to your
157+
/// consumers that they need to consider correctness in the face of unwinds.
158+
///
159+
/// If an unwind would be unsound, then this function should be used in order
160+
/// to prevent unwinds. However, note that `extern "C" fn` will automatically
161+
/// convert unwinds to aborts, so using this function isn't necessary for FFI.
162+
#[unstable(feature = "abort_unwind", issue = "130338")]
163+
#[rustc_nounwind]
164+
pub fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R {
165+
f()
166+
}
167+
143168
/// An internal trait used by std to pass data from std to `panic_unwind` and
144169
/// other panic runtimes. Not intended to be stabilized any time soon, do not
145170
/// use.

library/std/src/panic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ where
283283
{
284284
}
285285

286+
#[unstable(feature = "abort_unwind", issue = "130338")]
287+
pub use core::panic::abort_unwind;
288+
286289
/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
287290
///
288291
/// This function will return `Ok` with the closure's result if the closure

0 commit comments

Comments
 (0)