Closed
Description
Code
#![feature(core_intrinsics)]
use std::intrinsics::offset;
fn main() {
let a = [1u8, 2, 3];
let ptr: *const u8 = a.as_ptr();
unsafe {
assert_eq!(*offset(ptr, 0), 1);
}
}
Meta
rustc --version --verbose
:
$ rustc --version --verbose
rustc 1.71.0-nightly (e77366b57 2023-05-16)
binary: rustc
commit-hash: e77366b57b799dfa3ce1fcb850c068723a3213ee
commit-date: 2023-05-16
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
Error output
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in Item(DefId(0:4 ~ test[90e8]::main)) (after phase change to runtime-optimized) at bb1[1]:
Cannot offset by non-isize type i32
--> test.rs:9:21
|
9 | assert_eq!(*offset(ptr, 0), 1);
| ^^^^^^^^^^^^^^
|
= note: delayed at 0: <rustc_errors::HandlerInner>::emit_diagnostic
Backtrace
1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
2: <rustc_const_eval::transform::validate::TypeChecker>::fail::<alloc::string::String>
3: <rustc_const_eval::transform::validate::Validator as rustc_middle::mir::MirPass>::run_pass
4: rustc_mir_transform::optimized_mir
5: <rustc_query_impl::dynamic_query::optimized_mir::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
7: rustc_query_impl::get_query_non_incr::optimized_mir
8: rustc_monomorphize::collector::collect_neighbours
9: rustc_monomorphize::collector::collect_items_rec
10: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
11: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
12: rustc_monomorphize::collector::collect_crate_mono_items
13: rustc_monomorphize::partitioning::collect_and_partition_mono_items
14: <rustc_query_impl::dynamic_query::collect_and_partition_mono_items::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
16: rustc_query_impl::get_query_non_incr::collect_and_partition_mono_items
17: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
19: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
20: rustc_interface::passes::start_codegen
21: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
22: <rustc_interface::queries::Queries>::ongoing_codegen
23: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
24: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
25: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
26: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
27: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
28: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/e77366b57b799dfa3ce1fcb850c068723a3213ee/library/alloc/src/boxed.rs:1985:9
29: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
at /rustc/e77366b57b799dfa3ce1fcb850c068723a3213ee/library/alloc/src/boxed.rs:1985:9
30: std::sys::unix::thread::Thread::new::thread_start
at /rustc/e77366b57b799dfa3ce1fcb850c068723a3213ee/library/std/src/sys/unix/thread.rs:108:17
31: start_thread
at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
32: clone
at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.71.0-nightly (e77366b57 2023-05-16) running on x86_64-unknown-linux-gnu
query stack during panic:
end of query stack
Adding an isize
suffix fixes the issue:
assert_eq!(*offset(ptr, 0isize), 1);
The error first appears with the nightly-2023-04-29
toolchain. It works fine with nightly-2023-04-28
.