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: encode_const: unexpected type [usize; 1] with -Clto -Zsanitizer=cfi #100778

Closed
matthiaskrgr opened this issue Aug 19, 2022 · 7 comments · Fixed by #113708
Closed

ICE: encode_const: unexpected type [usize; 1] with -Clto -Zsanitizer=cfi #100778

matthiaskrgr opened this issue Aug 19, 2022 · 7 comments · Fixed by #113708
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-exploit-mitigations Project group: Exploit mitigations requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Aug 19, 2022

Code

#![feature(adt_const_params, generic_const_exprs)]
#![allow(incomplete_features)]

pub type Matrix = [usize; 1];
const EMPTY_MATRIX: Matrix = [0; 1];

pub struct Walk<const REMAINING: Matrix> { }

impl Walk<EMPTY_MATRIX> {
	pub const fn new() -> Self {
		Self {}
	}
}

fn main() {
    let _ = Walk::new();
}

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (0b79f758c 2022-08-18)
binary: rustc
commit-hash: 0b79f758c9aa6646606662a6d623a0752286cd17
commit-date: 2022-08-18
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Error output

rustc 97007.rs -Clto -Zsanitizer=cfi

<output>
Backtrace

error: internal compiler error: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs:159:9: encode_const: unexpected type `[usize; 1]`

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/compiler/rustc_errors/src/lib.rs:1393:9
stack backtrace:
   0:     0x7f2feed2f6d0 - std::backtrace_rs::backtrace::libunwind::trace::hdc27bfa6aa97f84d
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f2feed2f6d0 - std::backtrace_rs::backtrace::trace_unsynchronized::hd260a87da0307fa5
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2feed2f6d0 - std::sys_common::backtrace::_print_fmt::h789cb96c4a337f2c
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f2feed2f6d0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h36bc3de3612a60f5
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f2feed8a76e - core::fmt::write::h2db4bfe92ef037b0
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f2feed204d5 - std::io::Write::write_fmt::hcd345fc714a96537
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/io/mod.rs:1672:15
   6:     0x7f2feed32393 - std::sys_common::backtrace::_print::hcf53c28899e66110
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f2feed32393 - std::sys_common::backtrace::print::hd8ec3e1ae139ef7a
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f2feed32393 - std::panicking::default_hook::{{closure}}::he70b99e2f9e5bd44
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/panicking.rs:295:22
   9:     0x7f2feed3207f - std::panicking::default_hook::h8d91a23b91011754
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/panicking.rs:314:9
  10:     0x7f2ff1571644 - <rustc_driver[d9adb13473fd7853]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[97bb3a13db18d0cb]::ops::function::FnOnce<(&core[97bb3a13db18d0cb]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f2feed32bcd - std::panicking::rust_panic_with_hook::h5af783bc1124b2c1
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/panicking.rs:702:17
  12:     0x7f2ff250f3c1 - std[e5af5fec29962f4a]::panicking::begin_panic::<rustc_errors[713e2db940a8ff0d]::ExplicitBug>::{closure#0}
  13:     0x7f2ff250ebc6 - std[e5af5fec29962f4a]::sys_common::backtrace::__rust_end_short_backtrace::<std[e5af5fec29962f4a]::panicking::begin_panic<rustc_errors[713e2db940a8ff0d]::ExplicitBug>::{closure#0}, !>
  14:     0x7f2ff24eff46 - std[e5af5fec29962f4a]::panicking::begin_panic::<rustc_errors[713e2db940a8ff0d]::ExplicitBug>
  15:     0x7f2ff25349a6 - std[e5af5fec29962f4a]::panic::panic_any::<rustc_errors[713e2db940a8ff0d]::ExplicitBug>
  16:     0x7f2ff2533f0d - <rustc_errors[713e2db940a8ff0d]::HandlerInner>::bug::<&alloc[d0a20223ecbdb9c4]::string::String>
  17:     0x7f2ff2533c60 - <rustc_errors[713e2db940a8ff0d]::Handler>::bug::<&alloc[d0a20223ecbdb9c4]::string::String>
  18:     0x7f2ff255c23d - rustc_middle[151dce3d5e114089]::ty::context::tls::with_context_opt::<rustc_middle[151dce3d5e114089]::ty::context::tls::with_opt<rustc_middle[151dce3d5e114089]::util::bug::opt_span_bug_fmt<rustc_span[8d4f92e92ba5c24b]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  19:     0x7f2ff255e0a6 - rustc_middle[151dce3d5e114089]::util::bug::opt_span_bug_fmt::<rustc_span[8d4f92e92ba5c24b]::span_encoding::Span>
  20:     0x7f2fefefa803 - rustc_middle[151dce3d5e114089]::util::bug::bug_fmt
  21:     0x7f2ff203ad6a - rustc_symbol_mangling[b2898ddfc97b980c]::typeid::typeid_itanium_cxx_abi::encode_const
  22:     0x7f2ff203bab1 - rustc_symbol_mangling[b2898ddfc97b980c]::typeid::typeid_itanium_cxx_abi::encode_substs
  23:     0x7f2ff203cbbe - rustc_symbol_mangling[b2898ddfc97b980c]::typeid::typeid_itanium_cxx_abi::encode_ty
  24:     0x7f2ff203e2c4 - rustc_symbol_mangling[b2898ddfc97b980c]::typeid::typeid_itanium_cxx_abi::typeid_for_fnabi
  25:     0x7f2ff20514eb - rustc_symbol_mangling[b2898ddfc97b980c]::typeid::typeid_for_fnabi
  26:     0x7f2ff02b519e - <rustc_codegen_llvm[acf79596ac4c842c]::context::CodegenCx as rustc_codegen_ssa[7f70b03631c200c8]::traits::declare::PreDefineMethods>::predefine_fn
  27:     0x7f2ff1032d2d - rustc_codegen_llvm[acf79596ac4c842c]::base::compile_codegen_unit::module_codegen
  28:     0x7f2ff11986e9 - <rustc_query_system[2040a19449a5eda6]::dep_graph::graph::DepGraph<rustc_middle[151dce3d5e114089]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[151dce3d5e114089]::ty::context::TyCtxt, rustc_span[8d4f92e92ba5c24b]::symbol::Symbol, rustc_codegen_ssa[7f70b03631c200c8]::ModuleCodegen<rustc_codegen_llvm[acf79596ac4c842c]::ModuleLlvm>>
  29:     0x7f2ff1197389 - rustc_codegen_llvm[acf79596ac4c842c]::base::compile_codegen_unit
  30:     0x7f2ff1195a83 - rustc_codegen_ssa[7f70b03631c200c8]::base::codegen_crate::<rustc_codegen_llvm[acf79596ac4c842c]::LlvmCodegenBackend>
  31:     0x7f2ff119525e - <rustc_codegen_llvm[acf79596ac4c842c]::LlvmCodegenBackend as rustc_codegen_ssa[7f70b03631c200c8]::traits::backend::CodegenBackend>::codegen_crate
  32:     0x7f2ff0d5293c - <rustc_session[a8a0b865530ef14d]::session::Session>::time::<alloc[d0a20223ecbdb9c4]::boxed::Box<dyn core[97bb3a13db18d0cb]::any::Any>, rustc_interface[67a969eeca26ae2c]::passes::start_codegen::{closure#0}>
  33:     0x7f2ff0d52273 - <rustc_interface[67a969eeca26ae2c]::passes::QueryContext>::enter::<<rustc_interface[67a969eeca26ae2c]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[97bb3a13db18d0cb]::result::Result<alloc[d0a20223ecbdb9c4]::boxed::Box<dyn core[97bb3a13db18d0cb]::any::Any>, rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>
  34:     0x7f2ff0d49663 - <rustc_interface[67a969eeca26ae2c]::queries::Queries>::ongoing_codegen
  35:     0x7f2ff0d48701 - <rustc_interface[67a969eeca26ae2c]::interface::Compiler>::enter::<rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}::{closure#2}, core[97bb3a13db18d0cb]::result::Result<core[97bb3a13db18d0cb]::option::Option<rustc_interface[67a969eeca26ae2c]::queries::Linker>, rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>
  36:     0x7f2ff0d441bc - rustc_span[8d4f92e92ba5c24b]::with_source_map::<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_interface[67a969eeca26ae2c]::interface::create_compiler_and_run<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}>::{closure#1}>
  37:     0x7f2ff0d43ba2 - rustc_interface[67a969eeca26ae2c]::interface::create_compiler_and_run::<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}>
  38:     0x7f2ff0d42741 - <scoped_tls[e4311800d1c0ff57]::ScopedKey<rustc_span[8d4f92e92ba5c24b]::SessionGlobals>>::set::<rustc_interface[67a969eeca26ae2c]::interface::run_compiler<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}>::{closure#0}, core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>
  39:     0x7f2ff0d4242f - std[e5af5fec29962f4a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[67a969eeca26ae2c]::util::run_in_thread_pool_with_globals<rustc_interface[67a969eeca26ae2c]::interface::run_compiler<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}>::{closure#0}, core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>::{closure#0}, core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>
  40:     0x7f2ff1398e79 - <<std[e5af5fec29962f4a]::thread::Builder>::spawn_unchecked_<rustc_interface[67a969eeca26ae2c]::util::run_in_thread_pool_with_globals<rustc_interface[67a969eeca26ae2c]::interface::run_compiler<core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>, rustc_driver[d9adb13473fd7853]::run_compiler::{closure#1}>::{closure#0}, core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>::{closure#0}, core[97bb3a13db18d0cb]::result::Result<(), rustc_errors[713e2db940a8ff0d]::ErrorGuaranteed>>::{closure#1} as core[97bb3a13db18d0cb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f2feed3c9c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h374ee76b025338a5
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/alloc/src/boxed.rs:1935:9
  42:     0x7f2feed3c9c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2bee731a5ba86295
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/alloc/src/boxed.rs:1935:9
  43:     0x7f2feed3c9c3 - std::sys::unix::thread::Thread::new::thread_start::h44c172ae3f11ec1f
                               at /rustc/0b79f758c9aa6646606662a6d623a0752286cd17/library/std/src/sys/unix/thread.rs:108:17
  44:     0x7f2feea9978d - <unknown>
  45:     0x7f2feeb1a8e4 - clone
  46:                0x0 - <unknown>

note: 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: rustc 1.65.0-nightly (0b79f758c 2022-08-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -C lto -Z sanitizer=cfi

query stack during panic:
end of query stack
error: aborting due to previous error

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. labels Aug 19, 2022
@matthiaskrgr matthiaskrgr changed the title ICE: encode_const: unexpected type `[usize; 1] with -Clto -Zsanitizer=cfi ICE: encode_const: unexpected type [usize; 1] with -Clto -Zsanitizer=cfi Aug 19, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Aug 22, 2022
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Aug 24, 2022

Regression in db8086e added in #95548.

@matthiaskrgr
Copy link
Member Author

Hm so this has always crashed since the introduction of cfisan...?
Wouldn't really call this a regression then since there was no previous "working" state ^^

@rcvalle
Copy link
Member

rcvalle commented Aug 27, 2022

Thanks for finding and reporting it! I'll take a look at it soon.

@rcvalle
Copy link
Member

rcvalle commented Aug 27, 2022

@rustbot claim

@Noratrieb
Copy link
Member

@rcvalle any updates here?

@rcvalle
Copy link
Member

rcvalle commented Dec 20, 2022

@Nilstrieb Sorry for the delay on this. I've been working on rust-lang/rfcs#3296 and #105452 and I'll work on the known issues next.

@rcvalle rcvalle added the PG-exploit-mitigations Project group: Exploit mitigations label Apr 18, 2023
@matthiaskrgr
Copy link
Member Author

#![feature(adt_const_params)]

pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
    BYTES
}

pub fn main() {
    assert_eq!(
        function_with_bytes::<{ &[0x41, 0x41, 0x41, 0x41] }>(),
        b"AAAA"
    );
}

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 27, 2023
…ler-errors

CFI: Fix ICE: encode_const: unexpected type [usize

Fixes rust-lang#100778 and rust-lang#113366, and complements rust-lang#106547 by adding support for encoding const parameters.
@bors bors closed this as completed in 55dea62 Jul 27, 2023
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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-exploit-mitigations Project group: Exploit mitigations requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants