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

Elab bitfields: check size of type <=32bit rather than checking rank #387

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cparser/Elab.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ and elab_field_group env = function
| TInt(ik, _) -> ik
| TEnum(_, _) -> enum_ikind
| _ -> ILongLong (* trigger next error message *) in
if integer_rank ik > integer_rank IInt then begin
if sizeof_ikind ik > sizeof_ikind IInt then begin
error loc
"the type of bit-field '%a' must be an integer type no bigger than 'int'" pp_field id;
None,env
Expand Down
2 changes: 1 addition & 1 deletion test/regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TESTS=int32 int64 floats floats-basics floats-lit \
# Can run, but only in compiled mode, and have reference output in Results

TESTS_COMP=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \
bitfields5 bitfields6 bitfields7 bitfields8 \
bitfields5 bitfields6 bitfields7 bitfields8 bitfields_uint_t \
builtins-common builtins-$(ARCH) packedstruct1 packedstruct2 alignas \
varargs1 varargs2 varargs3 sections alias aligned

Expand Down
1 change: 1 addition & 0 deletions test/regression/Results/bitfields_uint_t
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = { a = 1, b = 2, c = 3, d = 4 }
22 changes: 22 additions & 0 deletions test/regression/bitfields_uint_t.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdint.h>

/* Test that uint32 type synonym works.
This previously failed for standard headers where uint32 is defined
as a (32-bit) unsigned long. */

struct s {
uint32_t a: 1;
uint32_t b: 2;
uint32_t c: 9;
uint32_t d: 20;
};

struct s x = { 1, 2, 3, 4 };

int main()
{
printf("x = { a = %d, b = %d, c = %d, d = %d }\n", x.a, x.b, x.c, x.d);
}