diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-30 08:03:01 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-30 08:03:01 +0000 |
| commit | ee47fe31e7ca4755fed8e26228522a93f3e59333 (patch) | |
| tree | bd0400927ee9c4cb3ada94087f7c7e81928dc0e6 /tests | |
| parent | 032755a0f56d3941855c576404e393dc280ce6bb (diff) | |
tests/lint: extend test for sizeof and offsetof
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/usr.bin/xlint/lint1/expr_sizeof.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/usr.bin/xlint/lint1/expr_sizeof.c b/tests/usr.bin/xlint/lint1/expr_sizeof.c index 05463ba603e..a21f84100bd 100644 --- a/tests/usr.bin/xlint/lint1/expr_sizeof.c +++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c @@ -1,4 +1,4 @@ -/* $NetBSD: expr_sizeof.c,v 1.7 2023/06/30 07:18:02 rillig Exp $ */ +/* $NetBSD: expr_sizeof.c,v 1.8 2023/06/30 08:03:01 rillig Exp $ */ # 3 "expr_sizeof.c" /* @@ -112,6 +112,29 @@ bit_fields(void) } cross_storage_unit; /* expect+1: error: negative array dimension (-16) [20] */ typedef int sizeof_cross_storage_unit[-(int)sizeof(cross_storage_unit)]; + + /* + * The bit-fields in a struct may be merged into the same storage + * units, even if their types differ. GCC 10, Clang 15 and lint all + * agree in packing the bit-fields and the char into 4 bytes, even + * though their underlying types + */ + struct mixed { + _Bool flag0:1; + signed int signed0:1; + unsigned int unsigned0:1; + char ch; + _Bool flag1:1; + signed int signed1:1; + unsigned int unsigned1:1; + } mixed; + /* expect+1: error: negative array dimension (-4) [20] */ + typedef int sizeof_mixed[-(int)sizeof(mixed)]; + /* FIXME: Implement build_offsetof correctly. */ + /* expect+3: error: negative array dimension (-4) [20] */ + typedef int offsetof_mixed_ch[ + -(int)__builtin_offsetof(struct mixed, ch) + ]; } /* |
