Skip to content

Conversation

@1c3t3a
Copy link
Member

@1c3t3a 1c3t3a commented Jul 23, 2025

This change extends the previously added enum discriminant check to enums read through a union or pointer. At the moment we only insert the check when transmuting to an enum. Although I hoped for it, this check isn't yet inserted for calls to MaybeUninit::assume_init, because the pass is running on polymorphic MIR and thus doesn't have the information yet to know whether the type that is read is an enum.

This is related to #143087.

r? @saethlin

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 23, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 23, 2025
@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from ccd9d59 to ec30c0d Compare July 23, 2025 13:21
@rust-log-analyzer

This comment has been minimized.

@1c3t3a

This comment was marked as outdated.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from ec30c0d to 852275f Compare July 24, 2025 08:34
@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from 852275f to aeaa360 Compare July 24, 2025 13:18
@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from aeaa360 to 34076b4 Compare July 24, 2025 14:21
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch 2 times, most recently from e9cba62 to 8ae0303 Compare August 6, 2025 13:29
@rust-log-analyzer

This comment has been minimized.

@saethlin saethlin added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 20, 2025
@saethlin
Copy link
Member

CI doesn't pass, so I'm setting this to waiting on author. If that's wrong and you want help with getting CI to pass, give a shout.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from 8ae0303 to bae1afd Compare November 4, 2025 10:21
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

This change extends the previously added enum discriminant check to
enums read through a union or pointer. At the moment we only insert
the check when transmuting to an enum. Although I hoped for it, this
check isn't yet inserted for calls to `MaybeUninit::assume_init`,
because the pass is running on polymorphic MIR and thus doesn't have
the information yet to know whether the type that is read is an
enum.
@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from bae1afd to a969bf9 Compare November 4, 2025 10:40
@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_nounwind_fmt
   2: core::panicking::panic_invalid_enum_construction
   3: <rustc_borrowck::type_check::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_statement
   4: <rustc_borrowck::type_check::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_body
   5: rustc_borrowck::type_check::type_check
   6: rustc_borrowck::borrowck_collect_region_constraints
   7: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
   8: rustc_borrowck::mir_borrowck
      [... omitted 3 frames ...]
   9: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 3 frames ...]
  10: rustc_mir_transform::mir_for_ctfe
      [... omitted 3 frames ...]
  11: rustc_mir_transform::optimized_mir
      [... omitted 3 frames ...]
  12: rustc_mir_transform::deduce_param_attrs::deduced_param_attrs
      [... omitted 3 frames ...]
  13: rustc_ty_utils::abi::fn_abi_new_uncached
  14: rustc_ty_utils::abi::fn_abi_of_instance
      [... omitted 3 frames ...]
  15: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine> as rustc_middle::ty::layout::FnAbiOf>::fn_abi_of_instance
  16: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_callee_and_args
  17: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_terminator
  18: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider
      [... omitted 3 frames ...]
  19: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  20: rustc_data_structures::sync::parallel::par_for_each_in::<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}>
  21: rustc_hir_analysis::check_crate
  22: rustc_interface::passes::analysis
      [... omitted 3 frames ...]
  23: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  24: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  25: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  26: <alloc::boxed::Box<dyn for<'a> core::ops::function::FnOnce<(&'a rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &'a std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena<'a>>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option<rustc_interface::queries::Linker>>> as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once
  27: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  28: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  29: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---
warning: the ICE couldn't be written to `/checkout/rustc-ice-2025-11-04T11_06_23-34266.txt`: Read-only file system (os error 30)

note: rustc 1.93.0-nightly (15fc12aef 2025-11-04) running on aarch64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C opt-level=3 -C embed-bitcode=no -C debug-assertions=on -C symbol-mangling-version=v0 -Z randomize-layout -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C link-arg=-L/usr/lib/llvm-20/lib -C llvm-args=-import-instr-limit=10 -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -Z binary-dep-depinfo -Z force-unstable-if-unmarked

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github`
#2 [mir_for_ctfe] caching mir of `prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github` for CTFE
#3 [optimized_mir] optimizing MIR for `prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github`
#4 [deduced_param_attrs] deducing parameter attributes for prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github
#5 [fn_abi_of_instance] computing call ABI of `prepare::<impl at compiler/rustc_codegen_cranelift/build_system/prepare.rs:69:1: 69:13>::github`
#6 [eval_static_initializer] evaluating initializer of static `abi_cafe::ABI_CAFE_REPO`
#7 [analysis] running analysis passes on crate `y`
end of query stack
thread caused non-unwinding panic. aborting.
[RUSTC-TIMING] y test:false 0.458
rustc exited with signal: 6 (SIGABRT) (core dumped)
error: could not compile `y` (bin "y")

Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc /checkout/obj/build/bootstrap/debug/rustc --crate-name y --edition=2021 compiler/rustc_codegen_cranelift/build_system/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C debug-assertions=on --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("unstable-features"))' -C metadata=ea7301ffeb7bb7c4 -C extra-filename=-c447049312def633 --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage3-codegen/aarch64-unknown-linux-gnu/release/deps --target aarch64-unknown-linux-gnu -L dependency=/checkout/obj/build/aarch64-unknown-linux-gnu/stage3-codegen/aarch64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/aarch64-unknown-linux-gnu/stage3-codegen/release/deps -Csymbol-mangling-version=v0 -Zrandomize-layout -Zunstable-options '--check-cfg=cfg(bootstrap)' -Zmacro-backtrace -Csplit-debuginfo=off -Clink-arg=-L/usr/lib/llvm-20/lib -Cllvm-args=-import-instr-limit=10 -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages -Z binary-dep-depinfo` (exit status: 254)
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 101
Created at: src/bootstrap/src/core/build_steps/test.rs:3682:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:3727:26

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:19:58
  local time: Tue Nov  4 11:06:23 UTC 2025
  network time: Tue, 04 Nov 2025 11:06:24 GMT
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants