Module Name: src Committed By: rillig Date: Fri Jun 30 08:03:02 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: expr_sizeof.c src/usr.bin/xlint/lint1: cgram.y Log Message: tests/lint: extend test for sizeof and offsetof To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/expr_sizeof.c cvs rdiff -u -r1.439 -r1.440 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/expr_sizeof.c diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.7 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.8 --- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.7 Fri Jun 30 07:18:02 2023 +++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c Fri Jun 30 08:03:01 2023 @@ -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) + ]; } /* Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.439 src/usr.bin/xlint/lint1/cgram.y:1.440 --- src/usr.bin/xlint/lint1/cgram.y:1.439 Thu Jun 29 22:52:44 2023 +++ src/usr.bin/xlint/lint1/cgram.y Fri Jun 30 08:03:01 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.439 2023/06/29 22:52:44 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.440 2023/06/30 08:03:01 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.439 2023/06/29 22:52:44 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.440 2023/06/30 08:03:01 rillig Exp $"); #endif #include <limits.h> @@ -405,6 +405,7 @@ primary_expression: } | generic_selection /* GCC primary-expression, see c_parser_postfix_expression */ + /* TODO: C99 7.17p3 allows not only an identifier but a designator. */ | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN { symtyp = FMEMBER; $$ = build_offsetof($3, getsym($5));