Skip to content

Commit

Permalink
Auto merge of rust-lang#129370 - matthiaskrgr:rollup-g9117ee, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#128727 (bump conflicting_repr_hints lint to be shown in dependencies)
 - rust-lang#129232 (Fix `thread::sleep` Duration-handling for ESP-IDF)
 - rust-lang#129321 (Change neutral element of <fNN as iter::Sum> to neg_zero)
 - rust-lang#129353 (llvm-wrapper: adapt for LLVM 20 API changes)
 - rust-lang#129363 (Force `LC_ALL=C` for all run-make tests)
 - rust-lang#129364 (safe transmute: gracefully bubble-up layout errors)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 21, 2024
2 parents 6b678c5 + 00e109f commit a32d4a0
Show file tree
Hide file tree
Showing 19 changed files with 250 additions and 58 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ declare_lint! {
Deny,
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
};
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,8 +1607,13 @@ extern "C" void LLVMRustComputeLTOCacheKey(RustStringRef KeyOut,
const auto &ExportList = Data->ExportLists.lookup(ModId);
const auto &ResolvedODR = Data->ResolvedODR.lookup(ModId);
const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(ModId);
#if LLVM_VERSION_GE(20, 0)
DenseSet<GlobalValue::GUID> CfiFunctionDefs;
DenseSet<GlobalValue::GUID> CfiFunctionDecls;
#else
std::set<GlobalValue::GUID> CfiFunctionDefs;
std::set<GlobalValue::GUID> CfiFunctionDecls;
#endif

// Based on the 'InProcessThinBackend' constructor in LLVM
for (auto &Name : Data->Index.cfiFunctionDefs())
Expand All @@ -1618,9 +1623,15 @@ extern "C" void LLVMRustComputeLTOCacheKey(RustStringRef KeyOut,
CfiFunctionDecls.insert(
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name)));

#if LLVM_VERSION_GE(20, 0)
Key = llvm::computeLTOCacheKey(conf, Data->Index, ModId, ImportList,
ExportList, ResolvedODR, DefinedGlobals,
CfiFunctionDefs, CfiFunctionDecls);
#else
llvm::computeLTOCacheKey(Key, conf, Data->Index, ModId, ImportList,
ExportList, ResolvedODR, DefinedGlobals,
CfiFunctionDefs, CfiFunctionDecls);
#endif

LLVMRustStringWriteImpl(KeyOut, Key.c_str(), Key.size());
}
18 changes: 7 additions & 11 deletions compiler/rustc_transmute/src/layout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub(crate) mod rustc {
};

use super::Tree;
use crate::layout::rustc::{Def, Ref};
use crate::layout::rustc::{layout_of, Def, Ref};

#[derive(Debug, Copy, Clone)]
pub(crate) enum Err {
Expand All @@ -206,7 +206,7 @@ pub(crate) mod rustc {
impl<'tcx> Tree<Def<'tcx>, Ref<'tcx>> {
pub fn from_ty(ty: Ty<'tcx>, cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, Err> {
use rustc_target::abi::HasDataLayout;
let layout = ty_layout(cx, ty);
let layout = layout_of(cx, ty)?;

if let Err(e) = ty.error_reported() {
return Err(Err::TypeError(e));
Expand Down Expand Up @@ -239,7 +239,7 @@ pub(crate) mod rustc {
let FieldsShape::Array { stride, count } = &layout.fields else {
return Err(Err::NotYetSupported);
};
let inner_layout = ty_layout(cx, *inner_ty);
let inner_layout = layout_of(cx, *inner_ty)?;
assert_eq!(*stride, inner_layout.size);
let elt = Tree::from_ty(*inner_ty, cx)?;
Ok(std::iter::repeat(elt)
Expand All @@ -254,7 +254,7 @@ pub(crate) mod rustc {
},

ty::Ref(lifetime, ty, mutability) => {
let layout = ty_layout(cx, *ty);
let layout = layout_of(cx, *ty)?;
let align = layout.align.abi.bytes_usize();
let size = layout.size.bytes_usize();
Ok(Tree::Ref(Ref {
Expand All @@ -280,7 +280,7 @@ pub(crate) mod rustc {
FieldsShape::Primitive => {
assert_eq!(members.len(), 1);
let inner_ty = members[0];
let inner_layout = ty_layout(cx, inner_ty);
let inner_layout = layout_of(cx, inner_ty)?;
Self::from_ty(inner_ty, cx)
}
FieldsShape::Arbitrary { offsets, .. } => {
Expand Down Expand Up @@ -413,7 +413,7 @@ pub(crate) mod rustc {
let padding = Self::padding(padding_needed.bytes_usize());

let field_ty = ty_field(cx, (ty, layout), field_idx);
let field_layout = ty_layout(cx, field_ty);
let field_layout = layout_of(cx, field_ty)?;
let field_tree = Self::from_ty(field_ty, cx)?;

struct_tree = struct_tree.then(padding).then(field_tree);
Expand Down Expand Up @@ -471,7 +471,7 @@ pub(crate) mod rustc {
|fields, (idx, field_def)| {
let field_def = Def::Field(field_def);
let field_ty = ty_field(cx, (ty, layout), idx);
let field_layout = ty_layout(cx, field_ty);
let field_layout = layout_of(cx, field_ty)?;
let field = Self::from_ty(field_ty, cx)?;
let trailing_padding_needed = layout.size - field_layout.size;
let trailing_padding = Self::padding(trailing_padding_needed.bytes_usize());
Expand All @@ -484,10 +484,6 @@ pub(crate) mod rustc {
}
}

pub(crate) fn ty_layout<'tcx>(cx: LayoutCx<'tcx, TyCtxt<'tcx>>, ty: Ty<'tcx>) -> Layout<'tcx> {
crate::layout::rustc::layout_of(cx, ty).unwrap()
}

fn ty_field<'tcx>(
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
Expand Down
13 changes: 3 additions & 10 deletions compiler/rustc_transmute/src/maybe_transmutable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,11 @@ mod rustc {
let Self { src, dst, assume, context } = self;

let layout_cx = LayoutCx { tcx: context, param_env: ParamEnv::reveal_all() };
let layout_of = |ty| {
crate::layout::rustc::layout_of(layout_cx, ty)
.map_err(|_| Err::NotYetSupported)
.and_then(|_| Tree::from_ty(ty, layout_cx))
};

// Convert `src` and `dst` from their rustc representations, to `Tree`-based
// representations. If these conversions fail, conclude that the transmutation is
// unacceptable; the layouts of both the source and destination types must be
// well-defined.
let src = layout_of(src);
let dst = layout_of(dst);
// representations.
let src = Tree::from_ty(src, layout_cx);
let dst = Tree::from_ty(dst, layout_cx);

match (src, dst) {
(Err(Err::TypeError(_)), _) | (_, Err(Err::TypeError(_))) => {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/iter/traits/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ macro_rules! float_sum_product {
impl Sum for $a {
fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
iter.fold(
0.0,
-0.0,
#[rustc_inherit_overflow_checks]
|a, b| a + b,
)
Expand All @@ -126,7 +126,7 @@ macro_rules! float_sum_product {
impl<'a> Sum<&'a $a> for $a {
fn sum<I: Iterator<Item=&'a Self>>(iter: I) -> Self {
iter.fold(
0.0,
-0.0,
#[rustc_inherit_overflow_checks]
|a, b| a + b,
)
Expand Down
27 changes: 27 additions & 0 deletions library/core/tests/num/float_iter_sum_identity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#[test]
fn f32_ref() {
let x: f32 = -0.0;
let still_x: f32 = [x].iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f32_own() {
let x: f32 = -0.0;
let still_x: f32 = [x].into_iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f64_ref() {
let x: f64 = -0.0;
let still_x: f64 = [x].iter().sum();
assert_eq!(1. / x, 1. / still_x)
}

#[test]
fn f64_own() {
let x: f64 = -0.0;
let still_x: f64 = [x].into_iter().sum();
assert_eq!(1. / x, 1. / still_x)
}
1 change: 1 addition & 0 deletions library/core/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod int_log;
mod ops;
mod wrapping;

mod float_iter_sum_identity;
mod ieee754;
mod nan;

Expand Down
30 changes: 24 additions & 6 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,32 @@ impl Thread {

#[cfg(target_os = "espidf")]
pub fn sleep(dur: Duration) {
let mut micros = dur.as_micros();
unsafe {
while micros > 0 {
let st = if micros > u32::MAX as u128 { u32::MAX } else { micros as u32 };
// ESP-IDF does not have `nanosleep`, so we use `usleep` instead.
// As per the documentation of `usleep`, it is expected to support
// sleep times as big as at least up to 1 second.
//
// ESP-IDF does support almost up to `u32::MAX`, but due to a potential integer overflow in its
// `usleep` implementation
// (https://github.com/espressif/esp-idf/blob/d7ca8b94c852052e3bc33292287ef4dd62c9eeb1/components/newlib/time.c#L210),
// we limit the sleep time to the maximum one that would not cause the underlying `usleep` implementation to overflow
// (`portTICK_PERIOD_MS` can be anything between 1 to 1000, and is 10 by default).
const MAX_MICROS: u32 = u32::MAX - 1_000_000 - 1;

// Add any nanoseconds smaller than a microsecond as an extra microsecond
// so as to comply with the `std::thread::sleep` contract which mandates
// implementations to sleep for _at least_ the provided `dur`.
// We can't overflow `micros` as it is a `u128`, while `Duration` is a pair of
// (`u64` secs, `u32` nanos), where the nanos are strictly smaller than 1 second
// (i.e. < 1_000_000_000)
let mut micros = dur.as_micros() + if dur.subsec_nanos() % 1_000 > 0 { 1 } else { 0 };

while micros > 0 {
let st = if micros > MAX_MICROS as u128 { MAX_MICROS } else { micros as u32 };
unsafe {
libc::usleep(st);

micros -= st as u128;
}

micros -= st as u128;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/run-make-support/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn run_common(name: &str, args: Option<&[&str]>) -> Command {
}
env::join_paths(paths.iter()).unwrap()
});
cmd.env("LC_ALL", "C"); // force english locale

if is_windows() {
let mut paths = vec![];
Expand Down Expand Up @@ -84,5 +85,6 @@ pub fn run_fail(name: &str) -> CompletedProcess {
pub fn cmd<S: AsRef<OsStr>>(program: S) -> Command {
let mut command = Command::new(program);
set_host_rpath(&mut command);
command.env("LC_ALL", "C"); // force english locale
command
}
14 changes: 14 additions & 0 deletions tests/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ error: aborting due to 3 previous errors

Some errors have detailed explanations: E0566, E0658.
For more information about an error, try `rustc --explain E0566`.
Future incompatibility report: Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/feature-gate-repr-simd.rs:4:8
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(simd)]
| ^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` on by default

25 changes: 25 additions & 0 deletions tests/ui/issues/issue-47094.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ LL | #[repr(u8)]
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0566`.
Future incompatibility report: Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:1:8
|
LL | #[repr(C, u8)]
| ^ ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` on by default

Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:8:8
|
LL | #[repr(C)]
| ^
LL |
LL | #[repr(u8)]
| ^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` on by default

22 changes: 22 additions & 0 deletions tests/ui/repr/conflicting-repr-hints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,25 @@ error: aborting due to 12 previous errors

Some errors have detailed explanations: E0566, E0587, E0634.
For more information about an error, try `rustc --explain E0566`.
Future incompatibility report: Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:13:8
|
LL | #[repr(C, u64)]
| ^ ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` on by default

Future breakage diagnostic:
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:19:8
|
LL | #[repr(u32, u64)]
| ^^^ ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
= note: `#[deny(conflicting_repr_hints)]` on by default

4 changes: 2 additions & 2 deletions tests/ui/transmutability/arrays/huge-len.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: `()` cannot be safely transmuted into `ExplicitlyPadded`
--> $DIR/huge-len.rs:21:41
|
LL | assert::is_maybe_transmutable::<(), ExplicitlyPadded>();
| ^^^^^^^^^^^^^^^^ analyzing the transmutability of `ExplicitlyPadded` is not yet supported
| ^^^^^^^^^^^^^^^^ values of the type `ExplicitlyPadded` are too big for the current architecture
|
note: required by a bound in `is_maybe_transmutable`
--> $DIR/huge-len.rs:8:14
Expand All @@ -17,7 +17,7 @@ error[E0277]: `ExplicitlyPadded` cannot be safely transmuted into `()`
--> $DIR/huge-len.rs:24:55
|
LL | assert::is_maybe_transmutable::<ExplicitlyPadded, ()>();
| ^^ analyzing the transmutability of `ExplicitlyPadded` is not yet supported
| ^^ values of the type `ExplicitlyPadded` are too big for the current architecture
|
note: required by a bound in `is_maybe_transmutable`
--> $DIR/huge-len.rs:8:14
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// An unknown destination type should be gracefully handled.

#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(incomplete_features)]

mod assert {
use std::mem::BikeshedIntrinsicFrom;

pub fn is_transmutable<Src, Dst>()
where
Dst: BikeshedIntrinsicFrom<Src>
{}
}

fn should_gracefully_handle_unknown_dst_field() {
#[repr(C)] struct Src;
#[repr(C)] struct Dst(Missing); //~ cannot find type
assert::is_transmutable::<Src, Dst>(); //~ ERROR cannot be safely transmuted
}

fn should_gracefully_handle_unknown_dst_ref_field() {
#[repr(C)] struct Src(&'static Src);
#[repr(C)] struct Dst(&'static Missing); //~ cannot find type
assert::is_transmutable::<Src, Dst>(); //~ ERROR cannot be safely transmuted
}
Loading

0 comments on commit a32d4a0

Please sign in to comment.