Skip to content

Commit

Permalink
Auto merge of rust-lang#131581 - tgross35:rollup-vul4kol, r=tgross35
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#124874 (intrinsics fmuladdf{32,64}: expose llvm.fmuladd.* semantics)
 - rust-lang#130962 (Migrate lib's `&Option<T>` into `Option<&T>`)
 - rust-lang#131289 (stabilize duration_consts_float)
 - rust-lang#131310 (Support clobber_abi in MSP430 inline assembly)
 - rust-lang#131546 (Make unused_parens's suggestion considering expr's attributes.)
 - rust-lang#131565 (Remove deprecation note in the `non_local_definitions` lint)
 - rust-lang#131576 (Flatten redundant test module `run_make_support::diff::tests::tests`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 12, 2024
2 parents fb20e4d + 5e477c9 commit 7b6e8c9
Show file tree
Hide file tree
Showing 41 changed files with 395 additions and 119 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ fn codegen_float_intrinsic_call<'tcx>(
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64),
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
sym::fmuladdf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32), // TODO: use cranelift intrinsic analogous to llvm.fmuladd.f32
sym::fmuladdf64 => ("fma", 3, fx.tcx.types.f64, types::F64), // TODO: use cranelift intrinsic analogous to llvm.fmuladd.f64
sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32, types::F32),
sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64, types::F64),
sym::floorf32 => ("floorf", 1, fx.tcx.types.f32, types::F32),
Expand Down Expand Up @@ -381,7 +384,7 @@ fn codegen_float_intrinsic_call<'tcx>(

let layout = fx.layout_of(ty);
let res = match intrinsic {
sym::fmaf32 | sym::fmaf64 => {
sym::fmaf32 | sym::fmaf64 | sym::fmuladdf32 | sym::fmuladdf64 => {
CValue::by_val(fx.bcx.ins().fma(args[0], args[1], args[2]), layout)
}
sym::copysignf32 | sym::copysignf64 => {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
sym::log2f64 => "log2",
sym::fmaf32 => "fmaf",
sym::fmaf64 => "fma",
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
sym::fmuladdf32 => "fmaf", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f32
sym::fmuladdf64 => "fma", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f64
sym::fabsf32 => "fabsf",
sym::fabsf64 => "fabs",
sym::minnumf32 => "fminf",
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,11 @@ impl<'ll> CodegenCx<'ll, '_> {
ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
ifn!("llvm.fma.f128", fn(t_f128, t_f128, t_f128) -> t_f128);

ifn!("llvm.fmuladd.f16", fn(t_f16, t_f16, t_f16) -> t_f16);
ifn!("llvm.fmuladd.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
ifn!("llvm.fmuladd.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
ifn!("llvm.fmuladd.f128", fn(t_f128, t_f128, t_f128) -> t_f128);

ifn!("llvm.fabs.f16", fn(t_f16) -> t_f16);
ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ fn get_simple_intrinsic<'ll>(
sym::fmaf64 => "llvm.fma.f64",
sym::fmaf128 => "llvm.fma.f128",

sym::fmuladdf16 => "llvm.fmuladd.f16",
sym::fmuladdf32 => "llvm.fmuladd.f32",
sym::fmuladdf64 => "llvm.fmuladd.f64",
sym::fmuladdf128 => "llvm.fmuladd.f128",

sym::fabsf16 => "llvm.fabs.f16",
sym::fabsf32 => "llvm.fabs.f32",
sym::fabsf64 => "llvm.fabs.f64",
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ pub fn check_intrinsic_type(
(0, 0, vec![tcx.types.f128, tcx.types.f128, tcx.types.f128], tcx.types.f128)
}

sym::fmuladdf16 => {
(0, 0, vec![tcx.types.f16, tcx.types.f16, tcx.types.f16], tcx.types.f16)
}
sym::fmuladdf32 => {
(0, 0, vec![tcx.types.f32, tcx.types.f32, tcx.types.f32], tcx.types.f32)
}
sym::fmuladdf64 => {
(0, 0, vec![tcx.types.f64, tcx.types.f64, tcx.types.f64], tcx.types.f64)
}
sym::fmuladdf128 => {
(0, 0, vec![tcx.types.f128, tcx.types.f128, tcx.types.f128], tcx.types.f128)
}

sym::fabsf16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
sym::fabsf32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
sym::fabsf64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,6 @@ lint_non_glob_import_type_ir_inherent = non-glob import of `rustc_type_ir::inher
lint_non_local_definitions_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`
lint_non_local_definitions_deprecation = this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks should be written at the same level as their item
.non_local = an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
.doctest = make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
);
}
}

diag.note(fluent::lint_non_local_definitions_deprecation);
}
NonLocalDefinitionsDiag::MacroRules {
depth,
Expand All @@ -1452,7 +1450,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
}

diag.note(fluent::lint_non_local);
diag.note(fluent::lint_non_local_definitions_deprecation);

if let Some(cargo_update) = cargo_update {
diag.subdiagnostic(cargo_update);
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,15 @@ trait UnusedDelimLint {
.find_ancestor_inside(value.span)
.map(|span| (value.span.with_hi(span.lo()), value.span.with_lo(span.hi()))),
ast::ExprKind::Paren(ref expr) => {
expr.span.find_ancestor_inside(value.span).map(|expr_span| {
// For the expr with attributes, like `let _ = (#[inline] || println!("Hello!"));`,
// the span should contains the attributes, or the suggestion will remove them.
let expr_span_with_attrs =
if let Some(attr_lo) = expr.attrs.iter().map(|attr| attr.span.lo()).min() {
expr.span.with_lo(attr_lo)
} else {
expr.span
};
expr_span_with_attrs.find_ancestor_inside(value.span).map(|expr_span| {
(value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi()))
})
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ symbols! {
fmt_debug,
fmul_algebraic,
fmul_fast,
fmuladdf128,
fmuladdf16,
fmuladdf32,
fmuladdf64,
fn_align,
fn_delegation,
fn_must_use,
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ pub enum InlineAsmClobberAbi {
RiscV,
LoongArch,
S390x,
Msp430,
}

impl InlineAsmClobberAbi {
Expand Down Expand Up @@ -946,6 +947,10 @@ impl InlineAsmClobberAbi {
"C" | "system" => Ok(InlineAsmClobberAbi::S390x),
_ => Err(&["C", "system"]),
},
InlineAsmArch::Msp430 => match name {
"C" | "system" => Ok(InlineAsmClobberAbi::Msp430),
_ => Err(&["C", "system"]),
},
_ => Err(&[]),
}
}
Expand Down Expand Up @@ -1125,6 +1130,11 @@ impl InlineAsmClobberAbi {
a8, a9, a10, a11, a12, a13, a14, a15,
}
},
InlineAsmClobberAbi::Msp430 => clobbered_regs! {
Msp430 Msp430InlineAsmReg {
r11, r12, r13, r14, r15,
}
},
}
}
}
53 changes: 53 additions & 0 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,59 @@ extern "rust-intrinsic" {
#[rustc_nounwind]
pub fn fmaf128(a: f128, b: f128, c: f128) -> f128;

/// Returns `a * b + c` for `f16` values, non-deterministically executing
/// either a fused multiply-add or two operations with rounding of the
/// intermediate result.
///
/// The operation is fused if the code generator determines that target
/// instruction set has support for a fused operation, and that the fused
/// operation is more efficient than the equivalent, separate pair of mul
/// and add instructions. It is unspecified whether or not a fused operation
/// is selected, and that may depend on optimization level and context, for
/// example.
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn fmuladdf16(a: f16, b: f16, c: f16) -> f16;
/// Returns `a * b + c` for `f32` values, non-deterministically executing
/// either a fused multiply-add or two operations with rounding of the
/// intermediate result.
///
/// The operation is fused if the code generator determines that target
/// instruction set has support for a fused operation, and that the fused
/// operation is more efficient than the equivalent, separate pair of mul
/// and add instructions. It is unspecified whether or not a fused operation
/// is selected, and that may depend on optimization level and context, for
/// example.
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn fmuladdf32(a: f32, b: f32, c: f32) -> f32;
/// Returns `a * b + c` for `f64` values, non-deterministically executing
/// either a fused multiply-add or two operations with rounding of the
/// intermediate result.
///
/// The operation is fused if the code generator determines that target
/// instruction set has support for a fused operation, and that the fused
/// operation is more efficient than the equivalent, separate pair of mul
/// and add instructions. It is unspecified whether or not a fused operation
/// is selected, and that may depend on optimization level and context, for
/// example.
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn fmuladdf64(a: f64, b: f64, c: f64) -> f64;
/// Returns `a * b + c` for `f128` values, non-deterministically executing
/// either a fused multiply-add or two operations with rounding of the
/// intermediate result.
///
/// The operation is fused if the code generator determines that target
/// instruction set has support for a fused operation, and that the fused
/// operation is more efficient than the equivalent, separate pair of mul
/// and add instructions. It is unspecified whether or not a fused operation
/// is selected, and that may depend on optimization level and context, for
/// example.
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn fmuladdf128(a: f128, b: f128, c: f128) -> f128;

/// Returns the absolute value of an `f16`.
///
/// The stabilized version of this intrinsic is
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
#![feature(const_unicode_case_lookup)]
#![feature(coverage_attribute)]
#![feature(do_not_recommend)]
#![feature(duration_consts_float)]
#![feature(internal_impls_macro)]
#![feature(ip)]
#![feature(is_ascii_octdigit)]
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ impl Duration {
#[stable(feature = "duration_float", since = "1.38.0")]
#[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_stable(feature = "duration_consts_float", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_secs_f64(&self) -> f64 {
(self.secs as f64) + (self.nanos.0 as f64) / (NANOS_PER_SEC as f64)
}
Expand All @@ -866,7 +866,7 @@ impl Duration {
#[stable(feature = "duration_float", since = "1.38.0")]
#[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_stable(feature = "duration_consts_float", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_secs_f32(&self) -> f32 {
(self.secs as f32) + (self.nanos.0 as f32) / (NANOS_PER_SEC as f32)
}
Expand All @@ -886,7 +886,7 @@ impl Duration {
#[unstable(feature = "duration_millis_float", issue = "122451")]
#[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")]
pub const fn as_millis_f64(&self) -> f64 {
(self.secs as f64) * (MILLIS_PER_SEC as f64)
+ (self.nanos.0 as f64) / (NANOS_PER_MILLI as f64)
Expand All @@ -907,7 +907,7 @@ impl Duration {
#[unstable(feature = "duration_millis_float", issue = "122451")]
#[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")]
pub const fn as_millis_f32(&self) -> f32 {
(self.secs as f32) * (MILLIS_PER_SEC as f32)
+ (self.nanos.0 as f32) / (NANOS_PER_MILLI as f32)
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl Duration {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_stable(feature = "duration_consts_float", since = "CURRENT_RUSTC_VERSION")]
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
let self_nanos = (self.secs as f64) * (NANOS_PER_SEC as f64) + (self.nanos.0 as f64);
let rhs_nanos = (rhs.secs as f64) * (NANOS_PER_SEC as f64) + (rhs.nanos.0 as f64);
Expand All @@ -1108,7 +1108,7 @@ impl Duration {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
#[rustc_const_stable(feature = "duration_consts_float", since = "CURRENT_RUSTC_VERSION")]
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
let self_nanos = (self.secs as f32) * (NANOS_PER_SEC as f32) + (self.nanos.0 as f32);
let rhs_nanos = (rhs.secs as f32) * (NANOS_PER_SEC as f32) + (rhs.nanos.0 as f32);
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#![feature(dec2flt)]
#![feature(duration_constants)]
#![feature(duration_constructors)]
#![feature(duration_consts_float)]
#![feature(error_generic_member_access)]
#![feature(exact_size_is_empty)]
#![feature(extern_types)]
Expand Down
14 changes: 7 additions & 7 deletions library/std/src/sys/pal/sgx/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ fn io_err_to_addr(result: io::Result<&SocketAddr>) -> io::Result<String> {
}
}

fn addr_to_sockaddr(addr: &Option<String>) -> io::Result<SocketAddr> {
addr.as_ref()
.ok_or(io::ErrorKind::AddrNotAvailable)?
fn addr_to_sockaddr(addr: Option<&str>) -> io::Result<SocketAddr> {
addr.ok_or(io::ErrorKind::AddrNotAvailable)?
.to_socket_addrs()
// unwrap OK: if an iterator is returned, we're guaranteed to get exactly one entry
.map(|mut it| it.next().unwrap())
Expand Down Expand Up @@ -161,11 +160,11 @@ impl TcpStream {
}

pub fn peer_addr(&self) -> io::Result<SocketAddr> {
addr_to_sockaddr(&self.peer_addr)
addr_to_sockaddr(self.peer_addr.as_deref())
}

pub fn socket_addr(&self) -> io::Result<SocketAddr> {
addr_to_sockaddr(&self.inner.local_addr)
addr_to_sockaddr(self.inner.local_addr.as_deref())
}

pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
Expand Down Expand Up @@ -255,13 +254,14 @@ impl TcpListener {
}

pub fn socket_addr(&self) -> io::Result<SocketAddr> {
addr_to_sockaddr(&self.inner.local_addr)
addr_to_sockaddr(self.inner.local_addr.as_deref())
}

pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
let (fd, local_addr, peer_addr) = usercalls::accept_stream(self.inner.inner.raw())?;
let peer_addr = Some(peer_addr);
let ret_peer = addr_to_sockaddr(&peer_addr).unwrap_or_else(|_| ([0; 4], 0).into());
let ret_peer =
addr_to_sockaddr(peer_addr.as_deref()).unwrap_or_else(|_| ([0; 4], 0).into());
Ok((TcpStream { inner: Socket::new(fd, local_addr), peer_addr }, ret_peer))
}

Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/pal/unix/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ impl Command {
}

#[allow(dead_code)]
pub fn get_cwd(&self) -> &Option<CString> {
&self.cwd
pub fn get_cwd(&self) -> Option<&CStr> {
self.cwd.as_deref()
}
#[allow(dead_code)]
pub fn get_uid(&self) -> Option<uid_t> {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl Command {
cvt(libc::setuid(u as uid_t))?;
}
}
if let Some(ref cwd) = *self.get_cwd() {
if let Some(cwd) = self.get_cwd() {
cvt(libc::chdir(cwd.as_ptr()))?;
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/process/process_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Command {
t!(cvt_r(|| libc::dup2(fd, libc::STDERR_FILENO)));
}

if let Some(ref cwd) = *self.get_cwd() {
if let Some(cwd) = self.get_cwd() {
t!(cvt(libc::chdir(cwd.as_ptr())));
}

Expand Down
11 changes: 6 additions & 5 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ fn run_test_in_process(
io::set_output_capture(None);

let test_result = match result {
Ok(()) => calc_result(&desc, Ok(()), &time_opts, &exec_time),
Err(e) => calc_result(&desc, Err(e.as_ref()), &time_opts, &exec_time),
Ok(()) => calc_result(&desc, Ok(()), time_opts.as_ref(), exec_time.as_ref()),
Err(e) => calc_result(&desc, Err(e.as_ref()), time_opts.as_ref(), exec_time.as_ref()),
};
let stdout = data.lock().unwrap_or_else(|e| e.into_inner()).to_vec();
let message = CompletedTest::new(id, desc, test_result, exec_time, stdout);
Expand Down Expand Up @@ -712,7 +712,8 @@ fn spawn_test_subprocess(
formatters::write_stderr_delimiter(&mut test_output, &desc.name);
test_output.extend_from_slice(&stderr);

let result = get_result_from_exit_code(&desc, status, &time_opts, &exec_time);
let result =
get_result_from_exit_code(&desc, status, time_opts.as_ref(), exec_time.as_ref());
(result, test_output, exec_time)
})();

Expand All @@ -724,8 +725,8 @@ fn run_test_in_spawned_subprocess(desc: TestDesc, runnable_test: RunnableTest) -
let builtin_panic_hook = panic::take_hook();
let record_result = Arc::new(move |panic_info: Option<&'_ PanicHookInfo<'_>>| {
let test_result = match panic_info {
Some(info) => calc_result(&desc, Err(info.payload()), &None, &None),
None => calc_result(&desc, Ok(()), &None, &None),
Some(info) => calc_result(&desc, Err(info.payload()), None, None),
None => calc_result(&desc, Ok(()), None, None),
};

// We don't support serializing TrFailedMsg, so just
Expand Down
Loading

0 comments on commit 7b6e8c9

Please sign in to comment.