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 in FieldPlacement::count atop 32-bit host with 64-bit target #57038

Closed
pnkfelix opened this issue Dec 21, 2018 · 0 comments · Fixed by #57042
Closed

ICE in FieldPlacement::count atop 32-bit host with 64-bit target #57038

pnkfelix opened this issue Dec 21, 2018 · 0 comments · Fixed by #57042
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Dec 21, 2018

While exploring building a cross-compiler and running the test suite on it, I found the following issue:

Using a config.toml with:

host = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]

and then doing x.py test eventually hits this problem:

./build/i686-unknown-linux-gnu/stage1/bin/rustc --target=x86_64-unknown-linux-gnu -O /tmp/huge-enum.rs
warning: unused variable: `big`
  --> /tmp/huge-enum.rs:23:9
   |
23 |     let big: Option<[u32; (1<<45)-1]> = None;
   |         ^^^ help: consider using `_big` instead
   |
   = note: #[warn(unused_variables)] on by default

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `4294967295`,
 right: `35184372088831`', src/librustc_target/abi/mod.rs:716:17
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

error: internal compiler error: unexpected panic

The reason for this ICE is due to a mistake in rustc's internal API here:

impl FieldPlacement {
pub fn count(&self) -> usize {
match *self {
FieldPlacement::Union(count) => count,
FieldPlacement::Array { count, .. } => {
let usize_count = count as usize;
assert_eq!(usize_count as u64, count);
usize_count
}
FieldPlacement::Arbitrary { ref offsets, .. } => offsets.len()
}
}

As @nagisa points out on Zulip, the compiler should not be using usize except for its own indices "and other memory-ey things"

@pnkfelix pnkfelix added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. P-low Low priority labels Dec 21, 2018
@nagisa nagisa added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority and removed P-low Low priority labels Dec 21, 2018
Centril added a commit to Centril/rust that referenced this issue Jan 12, 2019
…n-fieldplacement-count, r=michaelwoerister

Don't call `FieldPlacement::count` when count is too large

Sidestep ICE in `FieldPlacement::count` by not calling it when count will not fit in host's usize.

(I briefly played with trying to fix this by changing `FieldPlacement::count` to return a `u64`. However, based on how `FieldPlacement` is used, it seems like this would be a largely pointless pursuit... I'm open to counter-arguments, however.)

Fix rust-lang#57038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority 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.

2 participants