Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 tests/lint: extend test for sizeof and o...



details:   https://anonhg.NetBSD.org/src/rev/263a3d89c6e6
branches:  trunk
changeset: 377180:263a3d89c6e6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 30 08:03:01 2023 +0000

description:
tests/lint: extend test for sizeof and offsetof

diffstat:

 tests/usr.bin/xlint/lint1/expr_sizeof.c |  25 ++++++++++++++++++++++++-
 usr.bin/xlint/lint1/cgram.y             |   5 +++--
 2 files changed, 27 insertions(+), 3 deletions(-)

diffs (66 lines):

diff -r e2c0efba9f5b -r 263a3d89c6e6 tests/usr.bin/xlint/lint1/expr_sizeof.c
--- a/tests/usr.bin/xlint/lint1/expr_sizeof.c   Fri Jun 30 07:18:02 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c   Fri Jun 30 08:03:01 2023 +0000
@@ -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)
+       ];
 }
 
 /*
diff -r e2c0efba9f5b -r 263a3d89c6e6 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Jun 30 07:18:02 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Jun 30 08:03:01 2023 +0000
@@ -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));



Home | Main Index | Thread Index | Old Index