rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.1k stars 12.8k forks source link

ICE: "Unsigned value 0x10000 does not fit in 16 bits" with `#[repr(align(65536))]` on 16-bit target in release mode, different ICE in debug mode. #131122

Closed zachs18 closed 1 month ago

zachs18 commented 2 months ago

Code

// lib.rs
#![no_std]

#[repr(align(65536))]
struct Hello;

pub fn bar() -> usize { core::mem::align_of::<Hello>() }

Compile with cargo +nightly build -Z build-std=core --target avr-unknown-gnu-atmega328 --release (basically the same results with --target msp430-none-elf, also a 16-bit tier 3 target)

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (fb4aebddd 2024-09-30)
binary: rustc
commit-hash: fb4aebddd18d258046ddb51fd41589295259a0fa
commit-date: 2024-09-30
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

rustc-ice-2024-10-02T01_00_03-507058.txt

$ cargo +nightly build -Z build-std=core --target avr-unknown-gnu-atmega328 --release
   Compiling compiler_builtins v0.1.130
   Compiling core v0.0.0 (/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling avr-testing v0.1.0 (/tmp/avr-testing)
error: internal compiler error: /rustc/fb4aebddd18d258046ddb51fd41589295259a0fa/compiler/rustc_middle/src/mir/interpret/value.rs:139:32: Unsigned value 0x10000 does not fit in 16 bits

thread 'rustc' panicked at /rustc/fb4aebddd18d258046ddb51fd41589295259a0fa/compiler/rustc_middle/src/mir/interpret/value.rs:139:32:
Box<dyn Any>
stack backtrace:
   0:     0x7b30d60dbf7a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h700a654fe77e1f9c
   1:     0x7b30d68033e6 - core::fmt::write::ha8ac3a5009e0941e
   2:     0x7b30d79bcb51 - std::io::Write::write_fmt::h280500187b8ab992
   3:     0x7b30d60dbdd2 - std::sys::backtrace::BacktraceLock::print::h5b5702bc7edef58d
   4:     0x7b30d60de2f1 - std::panicking::default_hook::{{closure}}::h7c4c08203556436f
   5:     0x7b30d60de124 - std::panicking::default_hook::h4a5c0931e8301a2f
   6:     0x7b30d51a2d7f - std[170610031590a965]::panicking::update_hook::<alloc[66d4c008c69e86cd]::boxed::Box<rustc_driver_impl[26aaba0b9f674e85]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7b30d60dea08 - std::panicking::rust_panic_with_hook::hf9da426777cf33fb
   8:     0x7b30d51dcf11 - std[170610031590a965]::panicking::begin_panic::<rustc_errors[2b9f4ebbc725b026]::ExplicitBug>::{closure#0}
   9:     0x7b30d51cffb6 - std[170610031590a965]::sys::backtrace::__rust_end_short_backtrace::<std[170610031590a965]::panicking::begin_panic<rustc_errors[2b9f4ebbc725b026]::ExplicitBug>::{closure#0}, !>
  10:     0x7b30d51cb499 - std[170610031590a965]::panicking::begin_panic::<rustc_errors[2b9f4ebbc725b026]::ExplicitBug>
  11:     0x7b30d51e67a1 - <rustc_errors[2b9f4ebbc725b026]::diagnostic::BugAbort as rustc_errors[2b9f4ebbc725b026]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7b30d580cbd4 - rustc_middle[1155dac776b01d50]::util::bug::opt_span_bug_fmt::<rustc_span[d0163105bd3f350c]::span_encoding::Span>::{closure#0}
  13:     0x7b30d57f295a - rustc_middle[1155dac776b01d50]::ty::context::tls::with_opt::<rustc_middle[1155dac776b01d50]::util::bug::opt_span_bug_fmt<rustc_span[d0163105bd3f350c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7b30d57f27eb - rustc_middle[1155dac776b01d50]::ty::context::tls::with_context_opt::<rustc_middle[1155dac776b01d50]::ty::context::tls::with_opt<rustc_middle[1155dac776b01d50]::util::bug::opt_span_bug_fmt<rustc_span[d0163105bd3f350c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7b30d2dcd620 - rustc_middle[1155dac776b01d50]::util::bug::bug_fmt
  16:     0x7b30d72213ae - <rustc_mir_transform[de8989103c0dc9d3]::gvn::VnState>::insert
  17:     0x7b30d721479c - <rustc_mir_transform[de8989103c0dc9d3]::gvn::VnState>::simplify_rvalue
  18:     0x7b30d3ed1674 - <rustc_mir_transform[de8989103c0dc9d3]::gvn::GVN as rustc_mir_transform[de8989103c0dc9d3]::pass_manager::MirPass>::run_pass
  19:     0x7b30d680b98d - rustc_mir_transform[de8989103c0dc9d3]::pass_manager::run_passes_inner
  20:     0x7b30d71c8262 - rustc_mir_transform[de8989103c0dc9d3]::optimized_mir
  21:     0x7b30d71c6b1d - rustc_query_impl[180b75f2ddc39270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[180b75f2ddc39270]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7b30d682f438 - rustc_query_system[9f857c887a67b714]::query::plumbing::try_execute_query::<rustc_query_impl[180b75f2ddc39270]::DynamicConfig<rustc_query_system[9f857c887a67b714]::query::caches::DefIdCache<rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[180b75f2ddc39270]::plumbing::QueryCtxt, false>
  23:     0x7b30d682e9f3 - rustc_query_impl[180b75f2ddc39270]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7b30d6831816 - rustc_middle[1155dac776b01d50]::query::plumbing::query_get_at::<rustc_query_system[9f857c887a67b714]::query::caches::DefIdCache<rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 8usize]>>>
  25:     0x7b30d3f7c414 - rustc_mir_transform[de8989103c0dc9d3]::cross_crate_inline::cross_crate_inlinable
  26:     0x7b30d6b85005 - rustc_query_impl[180b75f2ddc39270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[180b75f2ddc39270]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7b30d6b833cb - rustc_query_system[9f857c887a67b714]::query::plumbing::try_execute_query::<rustc_query_impl[180b75f2ddc39270]::DynamicConfig<rustc_query_system[9f857c887a67b714]::query::caches::DefIdCache<rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[180b75f2ddc39270]::plumbing::QueryCtxt, false>
  28:     0x7b30d6b82f8a - rustc_query_impl[180b75f2ddc39270]::query_impl::cross_crate_inlinable::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7b30d71beb04 - rustc_passes[7a90872e0502ca71]::reachable::recursively_reachable
  30:     0x7b30d696b537 - rustc_passes[7a90872e0502ca71]::reachable::reachable_set
  31:     0x7b30d76808b8 - rustc_query_impl[180b75f2ddc39270]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[180b75f2ddc39270]::query_impl::reachable_set::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7b30d767f2b9 - rustc_query_system[9f857c887a67b714]::query::plumbing::try_execute_query::<rustc_query_impl[180b75f2ddc39270]::DynamicConfig<rustc_query_system[9f857c887a67b714]::query::caches::SingleCache<rustc_middle[1155dac776b01d50]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[180b75f2ddc39270]::plumbing::QueryCtxt, false>
  33:     0x7b30d767fade - rustc_query_impl[180b75f2ddc39270]::query_impl::reachable_set::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7b30d6f5e2a8 - <rustc_metadata[a1e01f1b85ceac18]::rmeta::encoder::EncodeContext>::encode_crate_root
  35:     0x7b30d7812393 - rustc_metadata[a1e01f1b85ceac18]::rmeta::encoder::encode_metadata
  36:     0x7b30d781a814 - rustc_metadata[a1e01f1b85ceac18]::fs::encode_and_write_metadata
  37:     0x7b30d7819603 - <rustc_interface[67c5fa7b03b13b84]::queries::Linker>::codegen_and_build_linker
  38:     0x7b30d750950b - rustc_interface[67c5fa7b03b13b84]::interface::run_compiler::<core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>, rustc_driver_impl[26aaba0b9f674e85]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7b30d7629650 - std[170610031590a965]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[67c5fa7b03b13b84]::util::run_in_thread_with_globals<rustc_interface[67c5fa7b03b13b84]::util::run_in_thread_pool_with_globals<rustc_interface[67c5fa7b03b13b84]::interface::run_compiler<core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>, rustc_driver_impl[26aaba0b9f674e85]::run_compiler::{closure#0}>::{closure#1}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>::{closure#0}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>
  40:     0x7b30d7629cba - <<std[170610031590a965]::thread::Builder>::spawn_unchecked_<rustc_interface[67c5fa7b03b13b84]::util::run_in_thread_with_globals<rustc_interface[67c5fa7b03b13b84]::util::run_in_thread_pool_with_globals<rustc_interface[67c5fa7b03b13b84]::interface::run_compiler<core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>, rustc_driver_impl[26aaba0b9f674e85]::run_compiler::{closure#0}>::{closure#1}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>::{closure#0}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d68a251df926a28b]::result::Result<(), rustc_span[d0163105bd3f350c]::ErrorGuaranteed>>::{closure#1} as core[d68a251df926a28b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7b30d762a0ab - std::sys::pal::unix::thread::Thread::new::thread_start::h5cf1ac2878833c32
  42:     0x7b30d189ca94 - start_thread
                               at ./nptl/pthread_create.c:447:8
  43:     0x7b30d1929c3c - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  44:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/avr-testing/rustc-ice-2024-10-02T01_00_03-507058.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C strip=debuginfo -Z unstable-options

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `bar`
#1 [cross_crate_inlinable] whether the item should be made inlinable across crates
end of query stack
error: could not compile `avr-testing` (lib)

Caused by:
  process didn't exit successfully: `/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name avr_testing --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=180 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=10bbcaf4572e942c -C extra-filename=-10bbcaf4572e942c --out-dir /home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps --target avr-unknown-gnu-atmega328 -C strip=debuginfo -L dependency=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps -L dependency=/home/zachary/opt_mount/zachary/cargo-target/release/deps --extern 'noprelude:compiler_builtins=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps/libcompiler_builtins-7fd167500327228b.rmeta' --extern 'noprelude:core=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps/libcore-fa3c34da63eafa79.rmeta' -Z unstable-options` (exit status: 101)
warning: build failed, waiting for other jobs to finish...
Backtrace

``` $ RUST_BACKTRACE=1 cargo +nightly build -Z build-std=core --target avr-unknown-gnu-atmega328 --release Compiling compiler_builtins v0.1.130 Compiling core v0.0.0 (/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core) Compiling rustc-std-workspace-core v1.99.0 (/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core) Compiling avr-testing v0.1.0 (/tmp/avr-testing) error: internal compiler error: /rustc/fb4aebddd18d258046ddb51fd41589295259a0fa/compiler/rustc_middle/src/mir/interpret/value.rs:139:32: Unsigned value 0x10000 does not fit in 16 bits thread 'rustc' panicked at /rustc/fb4aebddd18d258046ddb51fd41589295259a0fa/compiler/rustc_middle/src/mir/interpret/value.rs:139:32: Box stack backtrace: 0: std::panicking::begin_panic:: 1: ::emit_producing_guarantee 2: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0} 3: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 5: rustc_middle::util::bug::bug_fmt 6: ::insert 7: ::simplify_rvalue 8: ::run_pass 9: rustc_mir_transform::pass_manager::run_passes_inner 10: rustc_mir_transform::optimized_mir [... omitted 1 frame ...] 11: rustc_middle::query::plumbing::query_get_at::>> 12: rustc_mir_transform::cross_crate_inline::cross_crate_inlinable [... omitted 1 frame ...] 13: rustc_passes::reachable::recursively_reachable 14: rustc_passes::reachable::reachable_set [... omitted 1 frame ...] 15: ::encode_crate_root 16: rustc_metadata::rmeta::encoder::encode_metadata 17: rustc_metadata::fs::encode_and_write_metadata 18: ::codegen_and_build_linker 19: 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: 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: please make sure that you have updated to the latest nightly note: please attach the file at `/tmp/avr-testing/rustc-ice-2024-10-02T01_02_44-507394.txt` to your bug report note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C strip=debuginfo -Z unstable-options note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [optimized_mir] optimizing MIR for `bar` #1 [cross_crate_inlinable] whether the item should be made inlinable across crates #2 [reachable_set] reachability end of query stack error: could not compile `avr-testing` (lib) Caused by: process didn't exit successfully: `/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name avr_testing --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=180 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=10bbcaf4572e942c -C extra-filename=-10bbcaf4572e942c --out-dir /home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps --target avr-unknown-gnu-atmega328 -C strip=debuginfo -L dependency=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps -L dependency=/home/zachary/opt_mount/zachary/cargo-target/release/deps --extern 'noprelude:compiler_builtins=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps/libcompiler_builtins-7fd167500327228b.rmeta' --extern 'noprelude:core=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/release/deps/libcore-fa3c34da63eafa79.rmeta' -Z unstable-options` (exit status: 101) warning: build failed, waiting for other jobs to finish... ```


If you remove --release (and do [profile.dev.packages."*"] opt-level = 3 to make core not run out of registers when compiling), then you get a different ICE:

rustc-ice-2024-10-02T01_15_57-511791.txt

Error output

``` $ RUST_BACKTRACE=1 cargo +nightly build -Z build-std=core --target avr-unknown-gnu-atmega328 Compiling avr-testing v0.1.0 (/tmp/avr-testing) thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/common.rs:170:13: assertion failed: i < (1 << bit_size) stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: >::codegen_rvalue_operand 4: rustc_codegen_ssa::mir::codegen_mir:: 5: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen 6: ::compile_codegen_unit 7: ::codegen_crate 8: ::codegen_and_build_linker 9: 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: 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: please make sure that you have updated to the latest nightly note: please attach the file at `/tmp/avr-testing/rustc-ice-2024-10-02T01_15_57-511791.txt` to your bug report note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z unstable-options note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack error: could not compile `avr-testing` (lib) Caused by: process didn't exit successfully: `/home/zachary/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name avr_testing --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=180 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=ee58599ee021bb48 -C extra-filename=-ee58599ee021bb48 --out-dir /home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/debug/deps --target avr-unknown-gnu-atmega328 -C incremental=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/debug/incremental -L dependency=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/debug/deps -L dependency=/home/zachary/opt_mount/zachary/cargo-target/debug/deps --extern 'noprelude:compiler_builtins=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/debug/deps/libcompiler_builtins-c8a0592a6a11b0cd.rmeta' --extern 'noprelude:core=/home/zachary/opt_mount/zachary/cargo-target/avr-unknown-gnu-atmega328/debug/deps/libcore-3761d8d6676445dc.rmeta' -Z unstable-options` (exit status: 101) ```


Note that if you remove pub fn bar or make it non-pub it compiles.

#[repr(align(1 << N))] or higher should probably just give an unconditional error on (≤N)-bit targets (or maybe just anything that would determine its layout could error, similar to how core::mem::size_of::<[u8; 0x1_0000_0000_0000]>() fails to compile with "values of the type [u8; 281474976710656] are too big for the current architecture" on x86_64-unknown-linux-gnu, but type T = [u8; 0x1_0000_0000_0000]; alone is Fine™).

asquared31415 commented 2 months ago

@rustbot assign

rustbot commented 2 months ago

Error: Parsing assign command in comment failed: ...' assign' | error: specify user to assign to at >| ''...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

asquared31415 commented 2 months ago

@rustbot claim