Skip to content

ICE: the static const safety checks accepted mutable references they should not have accepted with const_heap and intrinsics #140268

New issue

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

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

Already on GitHub? # to your account

Closed
wychlw opened this issue Apr 24, 2025 · 4 comments
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

@wychlw
Copy link

wychlw commented Apr 24, 2025

The code is generated by a fuzzer and reduced manually. I tried to search similar issue but got no results.

Code

#![feature(core_intrinsics)]
#![feature(const_heap)]
use std::intrinsics;

const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (df35ff6c3 2025-04-23)
binary: rustc
commit-hash: df35ff6c354f1f1fbf430b84e7dea37dfe997f34
commit-date: 2025-04-23
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

error: internal compiler error: compiler/rustc_const_eval/src/interpret/intern.rs:267:21: the static const safety checks accepted mutable references they should not have accepted
 --> results/1.rs:5:1
  |
5 | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
  | ^^^^^^^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/intern.rs:267:21:
Box<dyn Any>
...
query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `BAR`
#1 [eval_to_const_value_raw] simplifying constant for the type system `BAR`
#2 [analysis] running analysis passes on this crate
end of query stack
Backtrace

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

error: internal compiler error: compiler/rustc_const_eval/src/interpret/intern.rs:267:21: the static const safety checks accepted mutable references they should not have accepted
 --> results/1.rs:5:1
  |
5 | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32 };
  | ^^^^^^^^^^^^^^^^^^^


thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/intern.rs:267:21:
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_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: 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::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}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: rustc_const_eval::interpret::intern::intern_const_alloc_recursive::<rustc_const_eval::const_eval::machine::CompileTimeMachine>
   8: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 1 frame ...]
   9: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 1 frame ...]
  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}>::{closure#2}::{closure#0}
  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.

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

note: please attach the file at `/home/lw/Work/rust/nfuzz2/rustc-ice-2025-04-24T21_06_36-1872530.txt` to your bug report

note: compiler flags: --crate-type lib

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

Please do teach me if I've done anything wrong :)

@wychlw wychlw 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 Apr 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 24, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Apr 24, 2025

ICEs using internal features such as intrinsics or lang_items are expected per MCP 620 (rust-lang/compiler-team#620) and will not be fixed (as the message at the bottom of the backtrace says: note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly).
Can you provide a version that does not need intrinsics to ICE?

@wychlw
Copy link
Author

wychlw commented Apr 25, 2025

Thank you for pointing out I'm reporting a internal feature! I'd add them into the filter lists too.
Currently I haven't found a producible case without const_allocate feature. I'll close this issue for now, until I have any updates.

Thanks for your time and help!

@wychlw wychlw closed this as completed Apr 25, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 25, 2025
@jieyouxu
Copy link
Member

Please read the fuzzing guidelines which covers this.

@wychlw
Copy link
Author

wychlw commented Apr 26, 2025

Please read the fuzzing guidelines which covers this.

Thanks for it! I've setup a filter with all unwanted feature and added to my program, and pay more attention following the guide as well :)

# for free to join this conversation on GitHub. Already have an account? # 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