diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-30 16:39:17 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-30 16:39:17 +0000 |
| commit | fdcc8cff871d19278241dae9c368bdb6c783d01a (patch) | |
| tree | 65124948be4691dc266b7c2b326675292bebd8b5 /tests | |
| parent | 5987d1575ebc2bc6cd5aa9ff1ff965729c49e612 (diff) | |
tests/lint: extend tests for sizeof and alignof
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/usr.bin/xlint/lint1/d_alignof.c | 11 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/expr_sizeof.c | 39 |
2 files changed, 47 insertions, 3 deletions
diff --git a/tests/usr.bin/xlint/lint1/d_alignof.c b/tests/usr.bin/xlint/lint1/d_alignof.c index 165cf572d2d..44afc975ba4 100644 --- a/tests/usr.bin/xlint/lint1/d_alignof.c +++ b/tests/usr.bin/xlint/lint1/d_alignof.c @@ -1,4 +1,4 @@ -/* $NetBSD: d_alignof.c,v 1.10 2023/06/30 09:26:03 rillig Exp $ */ +/* $NetBSD: d_alignof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $ */ # 3 "d_alignof.c" /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */ @@ -108,6 +108,9 @@ alignof_variants(void) /* expect+1: error: cannot take size/alignment of incomplete type [143] */ typedef int incomplete_enum[-(int)__alignof(enum incomplete_enum)]; + /* expect+1: error: cannot take size/alignment of incomplete type [143] */ + typedef int incomplete_array[-(int)__alignof(int[])]; + struct bit_fields { _Bool bit_field:1; }; @@ -117,7 +120,11 @@ alignof_variants(void) */ /* expect+2: error: cannot initialize typedef '00000000_tmp' [25] */ /* expect+1: error: cannot take size/alignment of bit-field [145] */ - typedef int bit_field[-(int)__alignof((struct bit_fields){0}.bit_field)]; + typedef int bit_field_1[-(int)__alignof((struct bit_fields){0}.bit_field)]; + + struct bit_fields bit_fields; + /* expect+1: error: cannot take size/alignment of bit-field [145] */ + typedef int bit_field_2[-(int)__alignof(bit_fields.bit_field)]; /* expect+1: error: cannot take size/alignment of void [146] */ typedef int plain_void[-(int)__alignof(void)]; diff --git a/tests/usr.bin/xlint/lint1/expr_sizeof.c b/tests/usr.bin/xlint/lint1/expr_sizeof.c index ce5d4f0225b..88b4edf987e 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.10 2023/06/30 15:19:09 rillig Exp $ */ +/* $NetBSD: expr_sizeof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $ */ # 3 "expr_sizeof.c" /* @@ -11,6 +11,7 @@ /* * A sizeof expression can either take a type name or an expression. */ + void sink(unsigned long); struct { @@ -164,3 +165,39 @@ anonymous_struct_and_union(void) /* expect+1: error: negative array dimension (-48) [20] */ typedef int sizeof_us_16_32[-(int)sizeof(us_16_32)]; } + + +void +sizeof_errors(void) +{ + /* expect+1: error: cannot take size/alignment of void [146] */ + typedef int sizeof_void[-(int)sizeof(void)]; + + /* + * A 'void array' gets replaced with an 'int array' before + * type_size_in_bits gets to see it, thus the 256 * 4 = 1024. + */ + /* expect+2: error: illegal use of 'void' [18] */ + /* expect+1: error: negative array dimension (-1024) [20] */ + typedef int sizeof_void_array[-(int)sizeof(void[256])]; + + /* expect+1: warning: enum 'incomplete_enum' never defined [235] */ + enum incomplete_enum; + /* expect+2: warning: cannot take size/alignment of incomplete type [143] */ + /* expect+1: error: negative array dimension (-4) [20] */ + typedef int sizeof_incomplete_enum[-(int)sizeof(enum incomplete_enum)]; +} + + +/* + * Due to the 'double' member, the alignment of this struct is 8, so the size + * has to be 24 (or at least divisible by 8), otherwise the 'double' member + * would not get the correct alignment in an array of this struct. + */ +struct s24 { + char c0; + double d8; + char c16; +}; +/* expect+1: error: negative array dimension (-24) [20] */ +typedef int sizeof_s24[-(int)sizeof(struct s24)]; |
