Skip to content

Extend the enum check to pointer and union reads - #144353

Open
1c3t3a wants to merge 2 commits into
rust-lang:mainfrom
1c3t3a:enum-check-enum-ptr
Open

1c3t3a wants to merge 2 commits into
rust-lang:mainfrom
1c3t3a:enum-check-enum-ptr

Conversation

@1c3t3a

@1c3t3a 1c3t3a commented Jul 23, 2025

Copy link
Copy Markdown
Member

View all comments

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

rustbot commented Jul 23, 2025

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

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

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

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

This comment has been minimized.

@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

rustbot commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

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

This comment has been minimized.

@rust-bors

This comment has been minimized.

@1c3t3a
1c3t3a force-pushed the enum-check-enum-ptr branch from e6f5eb3 to de6589b Compare February 19, 2026 15:03
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 de6589b to db5c944 Compare February 19, 2026 15:16
@rustbot

rustbot commented Feb 19, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@1c3t3a
1c3t3a force-pushed the enum-check-enum-ptr branch from db5c944 to 82ac9ba Compare February 19, 2026 16:06
@rust-log-analyzer

This comment has been minimized.

@1c3t3a
1c3t3a force-pushed the enum-check-enum-ptr branch from 82ac9ba to fbc7d13 Compare February 19, 2026 16:29
@rust-log-analyzer

This comment has been minimized.

@1c3t3a
1c3t3a force-pushed the enum-check-enum-ptr branch from fbc7d13 to 8579266 Compare February 19, 2026 18:03
@rust-log-analyzer

Copy link
Copy Markdown
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)
REPOSITORY                                   TAG       IMAGE ID       CREATED       SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    afc745c7535d   3 weeks ago   783MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:faae3d3a1dedd24cde388bb506bbacc0f7ed1eae99ebac129af66acd8540c84a
deleted: sha256:afc745c7535da1bb12f92c273b9a7e9c52c3f12c5873714b2542da259c6d9769
deleted: sha256:64e147d5e54d9be8b8aa322e511cda02296eda4b8b8d063c6a314833aca50e29
deleted: sha256:5cba409bb463f4e7fa1a19f695450170422582c1bc7c0e934d893b4e5f558bc6
deleted: sha256:cddc6ebd344b0111eaab170ead1dfda24acdfe865ed8a12599a34d338fa8e28b
deleted: sha256:2412c3f334d79134573cd45e657fb6cc0abd75bef3881458b0d498d936545c8d
---
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_nounwind_fmt
   2: core::panicking::panic_misaligned_pointer_dereference
   3: <rustc_middle::mir::syntax::Rvalue>::ty::<rustc_middle::mir::Body>
   4: <rustc_borrowck::type_check::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_statement
   5: <rustc_borrowck::type_check::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_body
   6: rustc_borrowck::type_check::type_check
   7: rustc_borrowck::borrowck_collect_region_constraints
   8: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
   9: rustc_borrowck::mir_borrowck
      [... omitted 2 frames ...]
  10: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 2 frames ...]
  11: rustc_mir_transform::mir_for_ctfe
      [... omitted 2 frames ...]
  12: rustc_mir_transform::optimized_mir
      [... omitted 2 frames ...]
  13: rustc_mir_transform::deduce_param_attrs::deduced_param_attrs
      [... omitted 2 frames ...]
  14: rustc_ty_utils::abi::fn_abi_new_uncached
  15: rustc_ty_utils::abi::fn_abi_of_instance
      [... omitted 2 frames ...]
  16: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine> as rustc_middle::ty::layout::FnAbiOf>::fn_abi_of_instance
  17: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_callee_and_args
  18: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_terminator
  19: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider
      [... omitted 2 frames ...]
  20: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  21: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<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}>::{closure#0}::{closure#1}::{closure#0}>>
  22: rustc_hir_analysis::check_crate
  23: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  24: <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}, 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>>
  25: <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}>
  26: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  27: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>>
  28: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  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-2026-02-19T18_34_06-39467.txt`: Read-only file system (os error 30)

note: rustc 1.95.0-nightly (183457d66 2026-02-19) 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 annotate-moves -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.439
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=7254b91c94d9ae57 -C extra-filename=-fe9a244d40edbf17 --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 -Zannotate-moves -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' -Z binary-dep-depinfo` (exit status: 254)
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run -Zwarnings --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=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:3877:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:3922: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:24:45
  local time: Thu Feb 19 18:34:06 UTC 2026
  network time: Thu, 19 Feb 2026 18:34:07 GMT
##[error]Process completed with exit code 1.

@rust-bors

rust-bors Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #153741) made this pull request unmergeable. Please resolve the merge conflicts.

This branch has not been deployed

No deployments
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