Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: assertion failed: end <= max_value at rustc_const_eval/src/interpret/validity.rs #138045

Closed
cushionbadak opened this issue Mar 5, 2025 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

#![feature(pattern_types)]
#![feature(pattern_type_macro)]

use std::pat::pattern_type;

const CHAR_OOB_PAT: pattern_type!(char is 'A'..'\u{0000}') = unsafe { std::mem::transmute('a') };

fn main() {}
Original Code (Mutant from Fuzzing)

//! Check that pattern types have their validity checked

#![feature(pattern_types)]
#![feature(pattern_type_macro)]

use std::pat::pattern_type;

const BAD: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
//~^ ERROR: it is undefined behavior to use this value

const BAD_UNINIT: pattern_type!(u32 is 1..) =
    //~^ ERROR: evaluation of constant value failed
    unsafe { std::mem::transmute(std::mem::MaybeUninit::<u32>::uninit()) };

const BAD_PTR: pattern_type!(usize is 1..) = unsafe { std::mem::transmute(&42) };
//~^ ERROR: evaluation of constant value failed

const BAD_AGGREGATE: (pattern_type!(u32 is 1..), u32) = (unsafe { std::mem::transmute(0) }, 0);
//~^ ERROR: it is undefined behavior to use this value

struct Foo(T, marker::PhantomData<U>);
struct Bar(pattern_type!(u32 is 1..));

const BAD_FOO: Foo = Foo(Bar(unsafe { std::mem::transmute(0) }));
//~^ ERROR: it is undefined behavior to use this value

const CHAR_UNINIT: pattern_type!(char is 'A'..'Z') =
    //~^ ERROR: evaluation of constant value failed
    unsafe { std::mem::transmute(std::mem::MaybeUninit::<u32>::uninit()) };

const CHAR_OOB_PAT: pattern_type!(char is 'A'..'\u{0000}') = unsafe { std::mem::transmute('a') };
//~^ ERROR: it is undefined behavior to use this value

const CHAR_OOB: pattern_type!(char is 'A'..'Z') = unsafe { std::mem::transmute(u32::MAX) };
//~^ ERROR: it is undefined behavior to use this value

fn main() {}


// /root/workspace/seeds_250301/tests/ui/type/pattern_types/validity.rs

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f9e0239a7 2025-03-04)
binary: rustc
commit-hash: f9e0239a7bc813b4aceffc7f069f4797cde3175c
commit-date: 2025-03-04
host: x86_64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

warning: the feature `pattern_types` is internal to the compiler or standard library
 --> 06F9.rs:1:12
  |
1 | #![feature(pattern_types)]
  |            ^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default


thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:805:9:
assertion failed: end <= max_value
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:805:9:
assertion failed: end <= max_value
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <rustc_const_eval::interpret::validity::ValidityVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::visit_scalar
   4: <rustc_const_eval::interpret::validity::ValidityVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine> as rustc_const_eval::interpret::visitor::ValueVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::visit_value
   5: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::validate_operand_internal
   6: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 2 frames ...]
   7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
   8: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 2 frames ...]
   9: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  10: rustc_hir_analysis::check_crate
  11: rustc_interface::passes::run_required_analyses
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  14: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/Volumes/T7/workspace/250305 scratch/codes/rustc-ice-2025-03-05T08_32_59-65432.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `CHAR_OOB_PAT`
#1 [eval_to_const_value_raw] simplifying constant for the type system `CHAR_OOB_PAT`
#2 [analysis] running analysis passes on this crate
end of query stack
warning: 1 warning emitted

Notes

  • ICE location: compiler/rustc_const_eval/src/interpret/validity.rs Line-805
    fn visit_scalar(
    &mut self,
    scalar: Scalar<M::Provenance>,
    scalar_layout: ScalarAbi,
    ) -> InterpResult<'tcx> {
    let size = scalar_layout.size(self.ecx);
    let valid_range = scalar_layout.valid_range(self.ecx);
    let WrappingRange { start, end } = valid_range;
    let max_value = size.unsigned_int_max();
    assert!(end <= max_value);

@rustbot label +F-pattern_types +F-pattern_type_macro

@cushionbadak cushionbadak added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 5, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 5, 2025
@matthiaskrgr
Copy link
Member

Closing as wontfix as the repro requires internal features.

@matthiaskrgr matthiaskrgr closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants