Skip to content

Packed struct #85

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

Closed
antoyo opened this issue Sep 25, 2021 · 4 comments
Closed

Packed struct #85

antoyo opened this issue Sep 25, 2021 · 4 comments
Assignees
Labels
libgccjit requires a change in libgccjit

Comments

@antoyo
Copy link
Contributor

antoyo commented Sep 25, 2021

No description provided.

@antoyo antoyo self-assigned this Sep 25, 2021
@antoyo antoyo added the libgccjit requires a change in libgccjit label Sep 25, 2021
@bjorn3
Copy link
Member

bjorn3 commented Jan 25, 2022

I think this is already supported. For

#[repr(packed)]
pub struct Foo(u8, u64, u64);

pub fn foo(v: Foo) -> Foo {
    v
}

//#[repr(packed)]
pub struct Bar(u8, u64, u64);

pub fn bar(v: Bar) -> Bar {
    v
}

the only difference between cg_llvm and cg_gcc seems to be different register selection choices, different instruction ordering and gcc using a potentially more efficient instruction for loading a single byte.

https://rust.godbolt.org/z/xdfKxo3v1

@antoyo
Copy link
Contributor Author

antoyo commented Jan 25, 2022

Are you sure that if you have such a struct in memory, it will have the correct size?

I thought it's not supported because I don't set the __packed__ attribute.

@bjorn3
Copy link
Member

bjorn3 commented Jan 25, 2022

I checked that statics work correctly: https://rust.godbolt.org/z/W9j1Y3j7M

Locals however don't work correctly:

#[repr(packed)]
pub struct Foo(u8, u64, u64);

pub fn foo(mut v: Foo) -> Foo {
    v.0 += 1;
    v.1 += 2; // cg_gcc uses offset 8 here while cg_llvm uses offset 1
    v
}

//#[repr(packed)]
pub struct Bar(u8, u64, u64);

pub fn bar(mut v: Bar) -> Bar {
    v.0 += 1;
    v.1 += 2;
    v
}

https://rust.godbolt.org/z/abEnddxbj

@bjorn3
Copy link
Member

bjorn3 commented Mar 30, 2022

Fixed by #148, right?

@antoyo antoyo closed this as completed Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgccjit requires a change in libgccjit
Projects
None yet
Development

No branches or pull requests

2 participants