Skip to content

Commit 34228cf

Browse files
committed
Auto merge of #164826 - JonathanBrouwer:rollup-jxYrOGV, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #163766 (Outline constant messages from panicking macros) - #147368 (Add extra `unchecked_disjoint_bitor` implementations.) - #164748 (Use 64-bit futex syscalls on RV32 Linux) - #164520 (powerpc: implement c-variadic correctly for softfloat targets) - #164671 (add maintainers for tier 2 riscv64 targets (baremetal only))
2 parents 9cd159c + 6ba97f9 commit 34228cf

22 files changed

Lines changed: 340 additions & 165 deletions

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,9 +2282,9 @@ checksum = "803ec87c9cfb29b9d2633f20cba1f488db3fd53f2158b1024cbefb47ba05d413"
22822282

22832283
[[package]]
22842284
name = "libc"
2285-
version = "0.2.189"
2285+
version = "0.2.191"
22862286
source = "registry+https://github.com/rust-lang/crates.io-index"
2287-
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
2287+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
22882288

22892289
[[package]]
22902290
name = "libffi"
@@ -2387,9 +2387,9 @@ dependencies = [
23872387

23882388
[[package]]
23892389
name = "linux-raw-sys"
2390-
version = "0.11.0"
2390+
version = "0.12.1"
23912391
source = "registry+https://github.com/rust-lang/crates.io-index"
2392-
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
2392+
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
23932393

23942394
[[package]]
23952395
name = "litemap"
@@ -5202,9 +5202,9 @@ dependencies = [
52025202

52035203
[[package]]
52045204
name = "rustix"
5205-
version = "1.1.2"
5205+
version = "1.1.5"
52065206
source = "registry+https://github.com/rust-lang/crates.io-index"
5207-
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
5207+
checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d"
52085208
dependencies = [
52095209
"bitflags",
52105210
"errno",

‎compiler/rustc_abi/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ impl fmt::Display for AlignFromBytesError {
11331133

11341134
impl Align {
11351135
pub const ONE: Align = Align { pow2: 0 };
1136+
pub const FOUR: Align = Align { pow2: 2 };
11361137
pub const EIGHT: Align = Align { pow2: 3 };
11371138
// LLVM has a maximal supported alignment of 2^29, we inherit that.
11381139
pub const MAX: Align = Align { pow2: 29 };

‎compiler/rustc_codegen_llvm/src/va_arg.rs‎

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_codegen_ssa::traits::{
99
use rustc_middle::ty::Ty;
1010
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
1111
use rustc_span::bug;
12-
use rustc_target::spec::{Arch, Env, LlvmAbi, RustcAbi};
12+
use rustc_target::spec::{Arch, Env, LlvmAbi, RustcAbi, Target};
1313

1414
use crate::builder::Builder;
1515
use crate::llvm::Value;
@@ -97,7 +97,13 @@ fn get_param_type_alignment<'ll, 'tcx>(
9797
Primitive::Float(float) => match float {
9898
Float::F16 | Float::F16B | Float::F32 => unreachable!(),
9999
Float::F64 | Float::F128 => { /* fall through */ }
100-
Float::PpcF128 => return Align::EIGHT,
100+
Float::PpcF128 => {
101+
return if is_powerpc_softfloat_abi(&bx.cx.tcx.sess.target) {
102+
Align::FOUR
103+
} else {
104+
Align::EIGHT
105+
};
106+
}
101107
},
102108
Primitive::Pointer(_) => { /* fall through */ }
103109
},
@@ -222,7 +228,7 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
222228
let on_stack = bx.append_sibling_block("va_arg.on_stack");
223229
let end = bx.append_sibling_block("va_arg.end");
224230
let zero = bx.const_i32(0);
225-
let offset_align = Align::from_bytes(4).unwrap();
231+
let offset_align = Align::FOUR;
226232

227233
let gr_type = layout.ty.is_any_ptr() || layout.ty.is_integral();
228234
let (reg_off, reg_top, slot_size) = if gr_type {
@@ -291,6 +297,19 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
291297
val
292298
}
293299

300+
fn is_powerpc_softfloat_abi(target: &Target) -> bool {
301+
if target.arch != Arch::PowerPC {
302+
return false;
303+
}
304+
305+
match target.rustc_abi {
306+
Some(RustcAbi::Softfloat) => bug!("there are currently no powerpc softfloat targets"),
307+
Some(RustcAbi::PowerPcSpe) => true, // SPE is like softfloat in terms of ABI
308+
None => false,
309+
Some(other) => bug!("unexpected powerpc abi {other:?}"),
310+
}
311+
}
312+
294313
fn emit_powerpc_va_arg<'ll, 'tcx>(
295314
bx: &mut Builder<'_, 'll, 'tcx>,
296315
list: OperandRef<'tcx, &'ll Value>,
@@ -310,26 +329,19 @@ fn emit_powerpc_va_arg<'ll, 'tcx>(
310329
// Peel off any newtype wrappers.
311330
let layout = layout.peel_transparent_wrappers_from_non_1zst(bx.cx);
312331

313-
// Rust does not currently support any powerpc softfloat targets.
314-
// FIXME: however, the SPE targets are softfloat-like, and the current
315-
// implementation doesn't handle them correctly.
316-
let target = &bx.cx.tcx.sess.target;
317-
let is_soft_float_abi = target.rustc_abi == Some(RustcAbi::Softfloat);
318-
assert!(!is_soft_float_abi);
319-
320332
// All instances of VaArgSafe are passed directly.
321333
let is_indirect = false;
322334

323-
let (is_i64, is_int, is_f64) = match layout.layout.backend_repr() {
335+
let is_int = match layout.layout.backend_repr() {
324336
BackendRepr::Scalar(scalar) => match scalar.primitive() {
325-
rustc_abi::Primitive::Int(integer, _) => (integer.size().bits() == 64, true, false),
326-
rustc_abi::Primitive::Float(float) => (false, false, matches!(float, Float::F64)),
327-
rustc_abi::Primitive::Pointer(_) => (false, true, false),
337+
rustc_abi::Primitive::Int(_, _) | rustc_abi::Primitive::Pointer(_) => true,
338+
rustc_abi::Primitive::Float(_) => false,
328339
},
329340
_ => unreachable!("all instances of VaArgSafe are represented as scalars"),
330341
};
331342

332-
let is_passed_in_fprs = !(is_int || is_soft_float_abi);
343+
let is_passed_in_fprs = !(is_int || is_powerpc_softfloat_abi(&bx.cx.tcx.sess.target));
344+
333345
let num_regs_addr = if !is_passed_in_fprs {
334346
va_list_addr // gpr
335347
} else {
@@ -339,7 +351,7 @@ fn emit_powerpc_va_arg<'ll, 'tcx>(
339351
let mut num_regs = bx.load(bx.type_i8(), num_regs_addr, dl.i8_align);
340352

341353
// "Align" the register count when the type is passed as `i64`.
342-
if is_i64 || (is_f64 && is_soft_float_abi) {
354+
if layout.size.bytes() == 8 && !is_passed_in_fprs {
343355
num_regs = bx.add(num_regs, bx.const_u8(1));
344356
num_regs = bx.and(num_regs, bx.const_u8(0b1111_1110));
345357
}
@@ -388,7 +400,7 @@ fn emit_powerpc_va_arg<'ll, 'tcx>(
388400
bx.store(bx.const_u8(max_regs), num_regs_addr, dl.i8_align);
389401

390402
// Everything in the overflow area is rounded up to a size of at least 4.
391-
let overflow_area_align = Align::from_bytes(4).unwrap();
403+
let overflow_area_align = Align::FOUR;
392404

393405
let size = if !is_indirect {
394406
layout.layout.size.align_to(overflow_area_align)
@@ -625,8 +637,8 @@ fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>(
625637
let gp_offset_ptr = va_list_addr;
626638
let fp_offset_ptr = bx.inbounds_ptradd(va_list_addr, bx.cx.const_usize(unsigned_int_offset));
627639

628-
let gp_offset_v = bx.load(bx.type_i32(), gp_offset_ptr, Align::from_bytes(8).unwrap());
629-
let fp_offset_v = bx.load(bx.type_i32(), fp_offset_ptr, Align::from_bytes(4).unwrap());
640+
let gp_offset_v = bx.load(bx.type_i32(), gp_offset_ptr, Align::EIGHT);
641+
let fp_offset_v = bx.load(bx.type_i32(), fp_offset_ptr, Align::FOUR);
630642

631643
let mut use_regs = bx.const_bool(false);
632644

@@ -759,7 +771,7 @@ fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>(
759771
if num_fp_registers > 0 {
760772
let offset = bx.const_u32(num_fp_registers * 16);
761773
let sum = bx.add(fp_offset_v, offset);
762-
bx.store(sum, fp_offset_ptr, Align::from_bytes(4).unwrap());
774+
bx.store(sum, fp_offset_ptr, Align::FOUR);
763775
}
764776

765777
bx.br(end);
@@ -872,11 +884,7 @@ fn emit_hexagon_va_arg_musl<'ll, 'tcx>(
872884
// Align current pointer based on argument type size (following LLVM's implementation)
873885
// Arguments <= 32 bits (4 bytes) use 4-byte alignment, > 32 bits use 8-byte alignment
874886
let type_size_bits = layout.size.bits();
875-
let arg_align = if type_size_bits > 32 {
876-
Align::from_bytes(8).unwrap()
877-
} else {
878-
Align::from_bytes(4).unwrap()
879-
};
887+
let arg_align = if type_size_bits > 32 { Align::EIGHT } else { Align::FOUR };
880888
let aligned_current = round_pointer_up_to_alignment(bx, current_ptr, arg_align);
881889

882890
// Calculate next pointer position (following LLVM's logic)
@@ -991,7 +999,7 @@ fn emit_xtensa_va_arg<'ll, 'tcx>(
991999
let offset = bx.load(bx.type_i32(), offset_ptr, bx.tcx().data_layout.i32_align);
9921000
let offset = round_up_to_alignment(bx, offset, layout.align.abi);
9931001

994-
let slot_size = layout.size.align_to(Align::from_bytes(4).unwrap()).bytes() as i32;
1002+
let slot_size = layout.size.align_to(Align::FOUR).bytes() as i32;
9951003

9961004
// Update the offset in va_list, by adding the slot's size.
9971005
let offset_next = bx.add(offset, bx.const_i32(slot_size));

‎library/core/src/bool.rs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! impl bool {}
22
3+
use crate::intrinsics;
34
use crate::marker::Destruct;
5+
use crate::ub_checks::assert_unsafe_precondition;
46

57
impl bool {
68
/// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
@@ -157,4 +159,50 @@ impl bool {
157159
pub const fn toggle(&mut self) {
158160
*self = !*self;
159161
}
162+
163+
/// Disjoint, bitwise or. Computes `self | rhs`, assuming at most one, true value.
164+
///
165+
/// Practically, this requires that `self | rhs` and `self ^ rhs` both yield the
166+
/// same result, allowing for any of the two to be emitted in codegen -- depending
167+
/// on whichever is cheapest.
168+
///
169+
/// # Examples
170+
///
171+
/// ```
172+
/// #![feature(disjoint_bitor)]
173+
///
174+
/// assert_eq!(
175+
/// // SAFETY: Only one, true value is passed.
176+
/// unsafe { false.unchecked_disjoint_bitor(true) },
177+
/// true,
178+
/// );
179+
///
180+
/// assert_eq!(
181+
/// // SAFETY: No true values are passed.
182+
/// unsafe { false.unchecked_disjoint_bitor(false) },
183+
/// false,
184+
/// );
185+
/// ```
186+
///
187+
/// # Safety
188+
///
189+
/// This results in undefined behaviour if both `self` and `rhs` are true.
190+
#[unstable(feature = "disjoint_bitor", issue = "135758")]
191+
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
192+
#[must_use = "this returns the result of the operation, \
193+
without modifying the original"]
194+
#[inline]
195+
pub const unsafe fn unchecked_disjoint_bitor(self, rhs: Self) -> Self {
196+
assert_unsafe_precondition!(
197+
check_language_ub,
198+
"bool::unchecked_disjoint_bitor cannot bitor two truths",
199+
(
200+
lhs: bool = self,
201+
rhs: bool = rhs,
202+
) => !(lhs & rhs),
203+
);
204+
205+
// SAFETY: Same precondition.
206+
unsafe { intrinsics::disjoint_bitor(self, rhs) }
207+
}
160208
}

‎library/core/src/macros/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ macro_rules! unreachable {
802802
#[rustc_diagnostic_opaque]
803803
macro_rules! unimplemented {
804804
() => {
805-
$crate::panicking::panic("not implemented")
805+
$crate::panicking::unimplemented_default_msg()
806806
};
807807
($($arg:tt)+) => {
808808
$crate::panic!("not implemented: {}", $crate::format_args!($($arg)+))
@@ -883,7 +883,7 @@ macro_rules! unimplemented {
883883
#[rustc_diagnostic_opaque]
884884
macro_rules! todo {
885885
() => {
886-
$crate::panicking::panic("not yet implemented")
886+
$crate::panicking::todo_default_msg()
887887
};
888888
($($arg:tt)+) => {
889889
$crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+))

‎library/core/src/num/int_macros.rs‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,49 @@ macro_rules! int_impl {
13251325
if b { imp::overflow_panic::rem() } else { a }
13261326
}
13271327

1328+
/// Disjoint, bitwise or. Computes `self | rhs`, assuming no overlapping one bits.
1329+
///
1330+
/// Practically, this requires that `self | rhs`, `self ^ rhs`, and `self + rhs` all
1331+
/// yield the same result, allowing for any of the three to be emitted in codegen --
1332+
/// depending on whichever is cheapest.
1333+
///
1334+
/// # Examples
1335+
///
1336+
/// ```
1337+
/// #![feature(disjoint_bitor)]
1338+
///
1339+
/// assert_eq!(
1340+
/// // SAFETY: `1` and `-2` have no ones in common.
1341+
#[doc = concat!(" unsafe { 1_", stringify!($SelfT), ".unchecked_disjoint_bitor(-2) },")]
1342+
/// -1,
1343+
/// );
1344+
/// ```
1345+
///
1346+
/// # Safety
1347+
///
1348+
/// This results in undefined behaviour if `self` and `rhs` have any overlapping one
1349+
/// bits, i.e. `lhs & rhs` must be zero.
1350+
///
1351+
/// Notably, this prevents both values from being negative.
1352+
#[unstable(feature = "disjoint_bitor", issue = "135758")]
1353+
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
1354+
#[must_use = "this returns the result of the operation, \
1355+
without modifying the original"]
1356+
#[inline]
1357+
pub const unsafe fn unchecked_disjoint_bitor(self, rhs: Self) -> Self {
1358+
assert_unsafe_precondition!(
1359+
check_language_ub,
1360+
concat!(stringify!($SelfT), "::unchecked_disjoint_bitor cannot bitor overlapping ones"),
1361+
(
1362+
lhs: $SelfT = self,
1363+
rhs: $SelfT = rhs,
1364+
) => (lhs & rhs) == 0,
1365+
);
1366+
1367+
// SAFETY: Same precondition.
1368+
unsafe { intrinsics::disjoint_bitor(self, rhs) }
1369+
}
1370+
13281371
/// Checked negation. Computes `-self`, returning `None` if `self == MIN`.
13291372
///
13301373
/// # Examples
@@ -2929,7 +2972,6 @@ macro_rules! int_impl {
29292972
}
29302973
}
29312974

2932-
29332975
/// Overflowing Euclidean remainder. Calculates `self.rem_euclid(rhs)`.
29342976
///
29352977
/// Returns a tuple of the remainder after dividing along with a boolean indicating whether an
@@ -2959,7 +3001,6 @@ macro_rules! int_impl {
29593001
}
29603002
}
29613003

2962-
29633004
/// Negates self, overflowing if this is equal to the minimum value.
29643005
///
29653006
/// Returns a tuple of the negated version of self along with a boolean indicating whether an overflow
@@ -3217,7 +3258,6 @@ macro_rules! int_impl {
32173258
q
32183259
}
32193260

3220-
32213261
/// Calculates the least nonnegative remainder of `self` when
32223262
/// divided by `rhs`.
32233263
///
@@ -4061,7 +4101,6 @@ macro_rules! int_impl {
40614101
traits::WidenTarget::internal_widen(self)
40624102
}
40634103

4064-
40654104
/// Converts `self` to the target integer type, saturating at the numeric
40664105
/// bounds instead of overflowing.
40674106
///

0 commit comments

Comments
 (0)