Elab bitfields: check size of type <=32bit rather than checking rank#387
Merged
xavierleroy merged 1 commit intoAbsInt:masterfrom Apr 19, 2021
amosr:amos/bitfield
Merged
Elab bitfields: check size of type <=32bit rather than checking rank#387xavierleroy merged 1 commit intoAbsInt:masterfrom amosr:amos/bitfield
xavierleroy merged 1 commit intoAbsInt:masterfrom
amosr:amos/bitfield
Conversation
When desugaring a bitfield, allow any integral type that is 32 bits or smaller. Previously this was checking the rank of the type rather than the size. This rank check caused issues with standard headers that declare `uint32_t` to be an `unsigned long` rather than an `unsigned int`. Here, any bitfields declared as `uint32_t` were failing to compile even though they are still actually 32 bits.
Contributor
|
Thank you for the suggestion and the code. I agree that CompCert should support more types for bitfields than allowed by the C standards, eventually. Right now I'm busy with teaching, but I'll come back to this issue and to your proposal in a few weeks. |
xavierleroy
approved these changes
Apr 19, 2021
Contributor
xavierleroy
left a comment
There was a problem hiding this comment.
Thank you for your patience and for this contribution. I like the proposed change: it makes bitfields more usable, while remaining within the limitations of CompCert's current bitfield packing schema. Merging now!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I had an issue with bitfields when using standard headers from newlib on ARM. The
uint32_ttypedef was defined asunsigned long, so the bitfield elaborator was complaining even though it was still only 32 bits. To fix this, I've changed the test in Elab.ml to check the size of the integer rather than the rank. I haven't gone through all the details of Bitfields.ml, but it looks like the logic depends on the size being <=32 rather than the rank, so I believe it is still correct.I've added a test case but this is a bit tricky to run automatically, since it relies on a specific 32-bit configuration. I also manually inspected the generated assembly for ARM-v7m and it was correct.
Issue 315 sounds superficially similar, but this is a much simpler change as it still only supports 32-bit values. This change just allows you to refer to them with another name.
Thanks,
Amos
When desugaring a bitfield, allow any integral type that is 32 bits
or smaller. Previously this was checking the rank of the type rather
than the size.
This rank check caused issues with standard headers that
declare
uint32_tto be anunsigned longrather than anunsigned int. Here, any bitfields declared asuint32_twerefailing to compile even though they are still actually 32 bits.