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

layout decided on a larger discriminant type (I32) than typeck (I16) #77806

Closed
piegamesde opened this issue Oct 10, 2020 · 3 comments · Fixed by #107592
Closed

layout decided on a larger discriminant type (I32) than typeck (I16) #77806

piegamesde opened this issue Oct 10, 2020 · 3 comments · Fixed by #107592
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-AVR Target: AVR processors (ATtiny, ATmega, etc.) O-msp430 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

@piegamesde
Copy link
Contributor

Code

#![no_std]
#![no_main]

extern crate panic_halt;

#[repr(C)]
enum Foo {
	Bar
}

#[arduino_uno::entry]
fn main() -> ! {
	loop {
	}
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (38d911dfc 2020-10-09)
binary: rustc
commit-hash: 38d911dfc55a7a1eea1c80139113ed2ff0151087
commit-date: 2020-10-09
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:1076:21: layout decided on a larger discriminant type (I32) than typeck (I16)

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945:9

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.49.0-nightly (38d911dfc 2020-10-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -C opt-level=s -C panic=abort -C lto -C debuginfo=2 -C debug-assertions=on -C incremental --crate-type bin

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

query stack during panic:
#0 [layout_raw] computing layout of `Foo`
#1 [lint_mod] linting top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

Backtrace

stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::layout_raw_uncached
   9: rustc_middle::ty::layout::layout_raw
  10: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::layout_raw>::compute
  11: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  12: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: rustc_query_system::query::plumbing::get_query_impl
  15: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  16: <rustc_lint::types::VariantSizeDifferences as rustc_lint::passes::LateLintPass>::check_item
  17: <rustc_lint::BuiltinCombinedModuleLateLintPass as rustc_lint::passes::LateLintPass>::check_item
  18: rustc_hir::intravisit::Visitor::visit_nested_item
  19: rustc_lint::late::late_lint_mod
  20: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::lint_mod>::compute
  21: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::get_query_impl
  25: rustc_query_system::query::plumbing::ensure_query_impl
  26: rustc_data_structures::sync::join
  27: rustc_session::utils::<impl rustc_session::session::Session>::time
  28: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  29: rustc_session::utils::<impl rustc_session::session::Session>::time
  30: rustc_interface::passes::analysis
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  32: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  33: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  34: rustc_data_structures::stack::ensure_sufficient_stack
  35: rustc_query_system::query::plumbing::get_query_impl
  36: rustc_interface::passes::QueryContext::enter
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  38: rustc_span::with_source_map
  39: rustc_interface::interface::create_compiler_and_run
  40: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@piegamesde piegamesde 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 Oct 10, 2020
@jonas-schievink jonas-schievink added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Oct 10, 2020
@jonas-schievink
Copy link
Contributor

MCVE:

#![no_std]
#![no_main]

#[repr(C)]
pub enum Foo {
    Bar,
}

And then use cargo +nightly build -Zbuild-std=core --target avr-unknown-gnu-atmega328 to build.

@jonas-schievink jonas-schievink added O-AVR Target: AVR processors (ATtiny, ATmega, etc.) A-layout Area: Memory layout of types requires-nightly This issue requires a nightly compiler in some way. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Oct 10, 2020
@jonas-schievink
Copy link
Contributor

Bug is presumably here:

if repr.c() {
match &tcx.sess.target.target.arch[..] {
// WARNING: the ARM EABI has two variants; the one corresponding
// to `at_least == I32` appears to be used on Linux and NetBSD,
// but some systems may use the variant corresponding to no
// lower bound. However, we don't run on those yet...?
"arm" => min_from_extern = Some(I32),
_ => min_from_extern = Some(I32),
}
}

I believe this should use the size of a C int instead, which on AVR is 16 bits.

@jonas-schievink
Copy link
Contributor

Heh, also happens when targeting msp430-none-elf (our other 16-bit target)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-AVR Target: AVR processors (ATtiny, ATmega, etc.) O-msp430 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.

3 participants