-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 with aligned enum #92464
Labels
A-codegen
Area: Code generation
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
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) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
MiSawa
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
Dec 31, 2021
FYI, also fails in stable |
Slightly different example, different error message, probably the same cause: #[repr(align(2))] // 2, 4, 8 crashes, 1 compiles
enum Aligned {
Zero = 0,
One = 1,
}
pub fn main() {
println!("{}", tou8(Aligned::Zero))
}
fn tou8(al: Aligned) -> u8 {
al as u8
}
|
So looks like we have that same problem both in the CTFE engine and in the codegen backend. Fun. At least we are consistent. ;) |
RalfJung
added
A-codegen
Area: Code generation
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
labels
Jan 3, 2022
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 3, 2022
Temporary fix for the layout of aligned enums Fix for the issue rust-lang#92464 ~~I was after this issue for quite some time now, I have a temporary fix for it. I think the current problem is [here](https://github.com/ouz-a/rust/blob/e75f96763f99d56d03ada939fe05cbeb2254888d/compiler/rustc_middle/src/ty/layout.rs#L1305-L1310) created `tag` value might be wrong, because when I checked `min` and `max` values it's always between 0..1, which results in wrong size comparison in a few lines down below. I think `min` and `max` values don't take `#[repr(aligned(8))]` into consideration and just act from base values assigned inside the enum. If what I am saying is true, aligned enums were created with the wrong layout for some time.~~ ~~As stated in the title this is only a temporary fix and I think this needs further investigation, if someone wants to mentor it I would like to work on that too.~~ 😸 **Edit: Weird some tests fail now going to close this for now...** **Edit2: I made it work again.** I think I figured out the main problem of the issue, layout types of aligned enums with custom discriminant types were not handled, which resulted in confusing(such as this issue) behavior down the line, this is a kinda hacky fix for the issue.
Fixed by #92932, closing. |
This was referenced May 7, 2022
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Jul 5, 2022
Fix repr(align) enum handling `enum`, for better or worse, supports `repr(align)`. That has already caused a bug in rust-lang#92464, which was "fixed" in rust-lang#92932, but it turns out that that fix is wrong and caused rust-lang#96185. So this reverts rust-lang#92932 (which fixes rust-lang#96185), and attempts another strategy for fixing rust-lang#92464: special-case enums when doing a cast, re-using the code to load the discriminant rather than assuming that the enum has scalar layout. This works fine for the interpreter. However, rust-lang#92464 contained another testcase that was previously not in the test suite -- and after adding it, it ICEs again. This is not surprising; codegen needs the same patch that I did in the interpreter. Probably this has to happen [around here](https://github.com/rust-lang/rust/blob/d32ce37a171663048a4c4a536803434e40f52bd6/compiler/rustc_codegen_ssa/src/mir/rvalue.rs#L276). Unfortunately I don't know how to do that -- the interpreter can load a discriminant from an operand, but codegen can only do that from a place. `@oli-obk` `@eddyb` `@bjorn3` any idea?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-codegen
Area: Code generation
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
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) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: