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

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @vakaras

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a

@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

⚠️ Warning ⚠️

@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from 557081f to 5bf5a01 Compare December 9, 2025 06:04
@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from 5bf5a01 to e167550 Compare December 9, 2025 07:12
@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@rust-log-analyzer

This comment has been minimized.

@1c3t3a 1c3t3a force-pushed the enum-check-enum-ptr branch from e167550 to e6f5eb3 Compare December 9, 2025 07:29
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
   Compiling addr2line v0.25.1
[RUSTC-TIMING] addr2line test:false 0.782
[RUSTC-TIMING] gimli test:false 5.996
[RUSTC-TIMING] object test:false 8.248
error: internal compiler error: /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:264:18: not immediate: OperandRef(Pair((ptr:@682 = private unnamed_addr constant [49 x i8] c"backtrace_rs::symbolize::gimli::Symbol<'{erased}>", align 1), (i64:i64 49)) @ TyAndLayout { ty: &str, layout: Layout { size: Size(16 bytes), align: AbiAlign { abi: Align(8 bytes) }, backend_repr: ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes)], memory_index: [0, 1] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 16 } })


thread 'rustc' (14048) panicked at /checkout/compiler/rustc_codegen_ssa/src/mir/operand.rs:264:18:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_codegen_ssa::mir::operand::OperandRef<&rustc_codegen_llvm::llvm::ffi::Value>>::immediate
   7: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>>::codegen_terminator
   8: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>
   9: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::<rustc_codegen_llvm::builder::GenericBuilder<rustc_codegen_llvm::context::FullCx>>
  10: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  11: rustc_codegen_llvm::base::compile_codegen_unit
  12: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  13: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  14: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  15: rustc_interface::passes::start_codegen
  16: <rustc_interface::queries::Linker>::codegen_and_build_linker
  17: <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>>
  18: <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}>
  19: <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}
  20: <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
  21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  22: <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}, ()>
  23: 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-12-09T07_43_39-14046.txt`: Read-only file system (os error 30)

note: rustc 1.94.0-nightly (7f4c408e2 2025-12-09) running on aarch64-unknown-linux-gnu

note: compiler flags: --crate-type dylib --crate-type rlib -C prefer-dynamic -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debug-assertions=on -Z unstable-options -C symbol-mangling-version=v0 -Z annotate-moves -Z randomize-layout -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -Z inline-mir -Z inline-mir-preserve-debug -Z mir_strip_debuginfo=locals-in-tiny-functions -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C embed-bitcode=yes -Z unstable-options -C force-frame-pointers=non-leaf -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked

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

query stack during panic:
end of query stack
[RUSTC-TIMING] std test:false 8.843
error: could not compile `std` (lib)

Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc /checkout/obj/build/bootstrap/debug/rustc --crate-name std --edition=2024 library/std/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type dylib --crate-type rlib --emit=dep-info,link -C prefer-dynamic -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --warn=unexpected_cfgs --check-cfg 'cfg(feature, values(any()))' --check-cfg 'cfg(target_has_reliable_f16)' --check-cfg 'cfg(target_has_reliable_f16_math)' --check-cfg 'cfg(target_has_reliable_f128)' --check-cfg 'cfg(target_has_reliable_f128_math)' -C debug-assertions=on --cfg 'feature="addr2line"' --cfg 'feature="backtrace"' --cfg 'feature="compiler-builtins-c"' --cfg 'feature="miniz_oxide"' --cfg 'feature="object"' --cfg 'feature="panic-unwind"' --cfg 'feature="std_detect_dlsym_getauxval"' --cfg 'feature="std_detect_file_io"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("addr2line", "backtrace", "backtrace-trace-only", "compiler-builtins-c", "compiler-builtins-mem", "compiler-builtins-no-f16-f128", "debug_refcell", "llvm-libunwind", "llvm_enzyme", "miniz_oxide", "object", "optimize_for_size", "panic-unwind", "std_detect_dlsym_getauxval", "std_detect_file_io", "system-llvm-libunwind", "windows_raw_dylib"))' -C metadata=90d66f7cebd9ccf1 -C extra-filename=-a138fc9a6bd3a976 --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps --target aarch64-unknown-linux-gnu -L dependency=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/release/deps --extern 'priv:addr2line=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libaddr2line-7d1a1ab9badac061.rlib' --extern alloc=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/liballoc-9a6fb56c153b5937.rlib --extern 'priv:cfg_if=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcfg_if-93442cd966425486.rlib' --extern core=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-20c07df90e53b4bc.rlib --extern 'priv:hashbrown=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libhashbrown-c6c2d690a4be9ec5.rlib' --extern libc=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/liblibc-d13a9b8dbb101e62.rlib --extern 'priv:miniz_oxide=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libminiz_oxide-bdd2995f78b26063.rlib' --extern 'priv:object=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libobject-fdf0bd3614b9a306.rlib' --extern 'priv:panic_abort=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libpanic_abort-637fc74e1e5a6c89.rlib' --extern 'priv:panic_unwind=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libpanic_unwind-d584c81c00e8c0a6.rlib' --extern 'priv:rustc_demangle=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/librustc_demangle-8f2d3e592ca9671b.rlib' --extern std_detect=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libstd_detect-d3ebe8aca8f9e556.rlib --extern 'priv:unwind=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libunwind-566c7c77a1921f61.rlib' -Z unstable-options -Csymbol-mangling-version=v0 -Zannotate-moves -Zrandomize-layout '--check-cfg=cfg(feature,values(any()))' -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=off -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 --cfg=randomized_layouts -Zinline-mir -Zinline-mir-preserve-debug -Zmir_strip_debuginfo=locals-in-tiny-functions -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages -Cembed-bitcode=yes -Zunstable-options -Cforce-frame-pointers=non-leaf '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo -L native=/checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/build/compiler_builtins-3b06131bc9323e87/out --cfg backtrace_in_libstd --check-cfg 'cfg(netbsd10)' --check-cfg 'cfg(restricted_std)' --check-cfg 'cfg(backtrace_in_libstd)'` (exit status: 101)
Bootstrap failed while executing `--stage 2 test --skip compiler --skip src`
Build completed unsuccessfully in 0:08:31
  local time: Tue Dec  9 07:43:48 UTC 2025
  network time: Tue, 09 Dec 2025 07:43:48 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