diff options
author | Amos Robinson <amos.robinson@gmail.com> | 2021-04-20 02:02:30 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 18:02:30 +0200 |
commit | 0877e32e0bb836a1b3b34d678f0c68f852c55ff3 (patch) | |
tree | d7996a0ce291e019f43adeac2b68d5918196fa88 /test | |
parent | 45af10b3ac30f8e4f5904824259b04df17e1c6b1 (diff) | |
download | compcert-kvx-0877e32e0bb836a1b3b34d678f0c68f852c55ff3.tar.gz compcert-kvx-0877e32e0bb836a1b3b34d678f0c68f852c55ff3.zip |
Elab bitfields: check size of type <=32bit rather than checking rank (#387)
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.
Co-authored-by: Amos Robinson <amos@gh.st>
Diffstat (limited to 'test')
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/bitfields_uint_t | 1 | ||||
-rw-r--r-- | test/regression/bitfields_uint_t.c | 22 |
3 files changed, 24 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile index 61c154a3..698c1392 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -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 diff --git a/test/regression/Results/bitfields_uint_t b/test/regression/Results/bitfields_uint_t new file mode 100644 index 00000000..f55071d0 --- /dev/null +++ b/test/regression/Results/bitfields_uint_t @@ -0,0 +1 @@ +x = { a = 1, b = 2, c = 3, d = 4 } diff --git a/test/regression/bitfields_uint_t.c b/test/regression/bitfields_uint_t.c new file mode 100644 index 00000000..3d7fb4e7 --- /dev/null +++ b/test/regression/bitfields_uint_t.c @@ -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); +} + + |