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

Repr attributes on ADTs do not have restrictions. #3352

Open
nobel-sh opened this issue Jan 6, 2025 · 2 comments
Open

Repr attributes on ADTs do not have restrictions. #3352

nobel-sh opened this issue Jan 6, 2025 · 2 comments

Comments

@nobel-sh
Copy link
Contributor

nobel-sh commented Jan 6, 2025

According to rust, the valid repr attributes are Rust (default), C, align, packed, transparent, simd, i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize and usize.
But gccrs allows us to use anything as the attribute and this code compiles without any error.

#[repr(this_repr_doesnot_exist)]
enum Starter{
    Bulbasaur,
    Charmander,
    Squirtle,
}

#[repr(!)]
enum Type{
    Grass,
    Fire,
    Water,
}

#[repr(hmmmmmmm)]
struct Stats {
    base_attack: u32,
    base_defense: u32,
    base_speed: u32,
}

fn main(){}

Godbolt: https://godbolt.org/z/f8rhET9ch

@CohenArthur
Copy link
Member

yeah we should probably do that in the attributes checker I think? would probably make sense, as for example repr(...) cannot use type aliases or anything like that: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=eb6470d9855df67c57f53619392970b8

@philberty
Copy link
Member

Yeah attributes checker makes sense then i think either directly in the backend where we have some repr support for packed and aligned for now. If this only works on builtin types then i think it should be handy enough to change the discriminant field type.

I am currently working on enums a fair bit these days I think our layout might be wrong after reviewing gdb code for a while again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants