From acd3542b8d4cf9b4bc1cf6c99f76bb2fb938fe20 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 19 Aug 2023 18:47:08 +0000 Subject: [PATCH 1/4] Don't do intra-pass validation on MIR shims --- compiler/rustc_mir_transform/src/shim.rs | 6 +++++- .../auxiliary/drop-shim-relates-opaque-aux.rs | 21 +++++++++++++++++++ .../drop-shim-relates-opaque-issue-114375.rs | 10 +++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs create mode 100644 tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 5e8ba4f544c97..603a829412be4 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -90,7 +90,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' }; debug!("make_shim({:?}) = untransformed {:?}", instance, result); - pm::run_passes( + // We don't validate MIR here because the shims may generate code that's + // only valid in a reveal-all param-env. However, since we do initial + // validation with the MirBuilt phase, which uses a user-facing param-env. + // This causes validation errors when TAITs are involved. + pm::run_passes_no_validate( tcx, &mut result, &[ diff --git a/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs new file mode 100644 index 0000000000000..54a22510066fe --- /dev/null +++ b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs @@ -0,0 +1,21 @@ +// crate foo + +#![feature(type_alias_impl_trait)] + +type Tait = impl Sized; +fn _constrain() -> Tait {} + +struct WrapperWithDrop(T); +impl Drop for WrapperWithDrop { + fn drop(&mut self) {} +} + +pub struct Foo(WrapperWithDrop); + +trait Id { + type Id: ?Sized; +} +impl Id for T { + type Id = T; +} +pub struct Bar(WrapperWithDrop<::Id>); diff --git a/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs new file mode 100644 index 0000000000000..51d2870497259 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs @@ -0,0 +1,10 @@ +// aux-build:drop-shim-relates-opaque-aux.rs +// compile-flags: -Zvalidate-mir --crate-type=lib +// build-pass + +extern crate drop_shim_relates_opaque_aux; + +pub fn drop_foo(_: drop_shim_relates_opaque_aux::Foo) {} +pub fn drop_bar(_: drop_shim_relates_opaque_aux::Bar) {} + +fn main() {} From 265c1b5d5025a1cb3bdc26b99f35317079a55c36 Mon Sep 17 00:00:00 2001 From: kadiwa Date: Tue, 22 Aug 2023 14:43:53 +0200 Subject: [PATCH 2/4] add regression test for not memcpying padding bytes --- .../{box-maybe-uninit.rs => box-uninit-bytes.rs} | 14 ++++++++++++++ 1 file changed, 14 insertions(+) rename tests/codegen/{box-maybe-uninit.rs => box-uninit-bytes.rs} (76%) diff --git a/tests/codegen/box-maybe-uninit.rs b/tests/codegen/box-uninit-bytes.rs similarity index 76% rename from tests/codegen/box-maybe-uninit.rs rename to tests/codegen/box-uninit-bytes.rs index 282af99b06736..732da0a179494 100644 --- a/tests/codegen/box-maybe-uninit.rs +++ b/tests/codegen/box-uninit-bytes.rs @@ -25,6 +25,20 @@ pub fn box_uninitialized2() -> Box> { Box::new(MaybeUninit::uninit()) } +#[repr(align(1024))] +pub struct LotsaPadding(usize); + +// Boxing a value with padding should not copy junk from the stack +#[no_mangle] +pub fn box_lotsa_padding() -> Box { + // CHECK-LABEL: @box_lotsa_padding + // CHECK-NOT: alloca + // CHECK-NOT: getelementptr + // CHECK-NOT: memcpy + // CHECK-NOT: memset + Box::new(LotsaPadding(42)) +} + // Hide the `allocalign` attribute in the declaration of __rust_alloc // from the CHECK-NOT above, and also verify the attributes got set reasonably. // CHECK: declare {{(dso_local )?}}noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]] From 6aef5b331ffcb6816fb8900f5e2d87948e7cff84 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Tue, 22 Aug 2023 15:29:10 +0000 Subject: [PATCH 3/4] Disable bootstrap rustc version check Mitigates #115065 --- src/bootstrap/config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 4821d20a89890..762e66ac7cc34 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1276,7 +1276,8 @@ impl Config { } config.initial_rustc = if let Some(rustc) = build.rustc { - config.check_build_rustc_version(&rustc); + // FIXME(#115065): re-enable this check + // config.check_build_rustc_version(&rustc); PathBuf::from(rustc) } else { config.download_beta_toolchain(); From 3977ed1e69e6fc14e76e19bead3d6d725fc2129d Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 22 Aug 2023 12:26:35 -0400 Subject: [PATCH 4/4] ArchiveWrapper: handle LLVM API update In llvm/llvm-project@f740bcb3707a17ed4ccd52157089011a586cc2a6 a boolean parameter changed to an enum. r? @nikic @rustbot label: +llvm-main --- compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp index 35d6b9ed7a44f..54fdc84c77d26 100644 --- a/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp @@ -203,7 +203,12 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers, } } +#if LLVM_VERSION_LT(18, 0) auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false); +#else + auto SymtabMode = WriteSymbtab ? SymtabWritingMode::NormalSymtab : SymtabWritingMode::NoSymtab; + auto Result = writeArchive(Dst, Members, SymtabMode, Kind, true, false); +#endif if (!Result) return LLVMRustResult::Success; LLVMRustSetLastError(toString(std::move(Result)).c_str());