-
Notifications
You must be signed in to change notification settings - Fork 786
Support repr(C) for rustified enums #3265
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
base: main
Are you sure you want to change the base?
Conversation
33d5339 to
1885dc0
Compare
Note addition of rust-lang#3265
emilio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! One nit
emilio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if we implement the suggested check for enum class Foo : uint8_t and so, we might not even need to add this switch? We could just repr(C) by default...
I think with this patch if you have something like:
enum class Foo : uint8_t {
};Using this option will miscompile it.
At the very least we should add a big warning on this option since it'd cause wrong struct layout.
I agree this would be good. However, it appears that LLVM does not expose the necessary APIs. Even if we exposed the necessary functionality, it would presumably only work for recent clang versions. Thoughts on how to proceed? |
Note addition of rust-lang#3265
ec7b724 to
d020ef1
Compare
|
What do you think of extending our layout tests to test the layout of enums? I think at least that would signal that there's something wrong with the generated code if you misuse this option. Other than that it looks good. |
|
Our |
d020ef1 to
61f39db
Compare
Note addition of rust-lang#3265
|
@thedataking Your added test doesn't touch the case of most concern for |
It is not possible to control the repr via custom attributes so add a new rustified enum variant which does not use repr(u*) or repr(i*). Using repr(C) is sometimes necessary to bindgen enums used in functions subject to cross-language CFI checks. Closes 3263. Link: https://rcvalle.com/docs/rust-cfi-design-doc/ Signed-off-by: Per Larsen <perlarsen@google.com>
Note addition of rust-lang#3265
623469e to
867ed28
Compare
Add layout tests for --rustified-repr-c-enum, covering short-enum widths and large enum values. Emit size/align asserts during codegen for enums. Signed-off-by: Per Larsen <perlarsen@google.com>
867ed28 to
a11cced
Compare
Good point, I added a test that requires the enum to have a 64-bit value. Any other cases of concern I should add? |
@emilio I've added test cases for |
In addition to
And maybe a "control" test for more usual-size enums without See rust-lang/rust#147017 for more on the issue here and the FCW that wound up landing. |
TODOs:
--rustified-non-exhaustive-repr-c-enumflag?Closes #3263.