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 lint: add more specific warning for bit-...



details:   https://anonhg.NetBSD.org/src/rev/5d257f9a1f6e
branches:  trunk
changeset: 379171:5d257f9a1f6e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 16 11:11:36 2021 +0000

description:
lint: add more specific warning for bit-field of type plain 'int'

Previously, declaring a bit-field of type plain 'int' resulted in this
warning:

        warning: nonportable bit-field type 'int' [34]

This warning was too unspecific to be actionable, and until yesterday it
didn't even include the type.  In order to allow this warning to be
understood and properly fixed, describe the actual nonportability more
precisely:

        warning: bit-field of type plain 'int' has
        implementation-defined signedness [344]

diffstat:

 distrib/sets/lists/tests/mi                |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile         |   4 ++--
 tests/usr.bin/xlint/lint1/msg_034.c        |  23 ++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_034.exp      |   3 ++-
 tests/usr.bin/xlint/lint1/msg_166.c        |   6 +++---
 tests/usr.bin/xlint/lint1/msg_166.exp      |   4 ++--
 tests/usr.bin/xlint/lint1/msg_344.c        |  24 ++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/msg_344.exp      |   1 +
 tests/usr.bin/xlint/lint1/t_integration.sh |   4 ++--
 usr.bin/xlint/lint1/decl.c                 |   8 ++++----
 usr.bin/xlint/lint1/err.c                  |   5 +++--
 11 files changed, 66 insertions(+), 20 deletions(-)

diffs (210 lines):

diff -r 10efba0c60e8 -r 5d257f9a1f6e distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun May 16 10:34:19 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun May 16 11:11:36 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1051 2021/05/16 00:09:49 rillig Exp $
+# $NetBSD: mi,v 1.1052 2021/05/16 11:11:36 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6891,6 +6891,8 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_342.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_343.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_343.exp                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_344.c                      tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_344.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/t_integration                  tests-usr.bin-tests     compattestfile,atf
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun May 16 11:11:36 2021 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.57 2021/05/15 19:12:14 rillig Exp $
+# $NetBSD: Makefile,v 1.58 2021/05/16 11:11:37 rillig Exp $
 
 NOMAN=         # defined
-MAX_MESSAGE=   343             # see lint1/err.c
+MAX_MESSAGE=   344             # see lint1/err.c
 
 .include <bsd.own.mk>
 
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_034.c
--- a/tests/usr.bin/xlint/lint1/msg_034.c       Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_034.c       Sun May 16 11:11:36 2021 +0000
@@ -1,11 +1,28 @@
-/*     $NetBSD: msg_034.c,v 1.4 2021/05/16 10:34:19 rillig Exp $       */
+/*     $NetBSD: msg_034.c,v 1.5 2021/05/16 11:11:37 rillig Exp $       */
 # 3 "msg_034.c"
 
 // Test for message: nonportable bit-field type '%s' [34]
 
-/* lint1-flags: -S -g -p -w */
+/* No -g since GCC allows all integer types as bit-fields. */
+/* lint1-flags: -S -p -w */
 
+/*
+ * C90 3.5.2.1 allows 'int', 'signed int', 'unsigned int' as bit-field types.
+ *
+ * C99 6.7.2.1 significantly changed the wording of the allowable types for
+ * bit-fields.  For example, 6.7.2.1p4 does not mention plain 'int' at all.
+ * The rationale for C99 6.7.2.1 mentions plain int though, and it would have
+ * broken a lot of existing code to disallow plain 'int' as a bit-field type.
+ * Footnote 104 explicitly mentions plain 'int' as well and it even allows
+ * typedef-types for bit-fields.
+ */
 struct example {
-       int nonportable: 1;             /* expect: 34 */
+       /* expect+1: 34 */
+       unsigned short ushort: 1;
+
+       /* expect+1: 344 */
+       int plain_int: 1;
+
+       signed int signed_int: 1;
        unsigned int portable: 1;
 };
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_034.exp
--- a/tests/usr.bin/xlint/lint1/msg_034.exp     Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_034.exp     Sun May 16 11:11:36 2021 +0000
@@ -1,1 +1,2 @@
-msg_034.c(9): warning: nonportable bit-field type 'int' [34]
+msg_034.c(21): warning: nonportable bit-field type 'unsigned short' [34]
+msg_034.c(24): warning: bit-field of type plain 'int' has implementation-defined signedness [344]
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_166.c
--- a/tests/usr.bin/xlint/lint1/msg_166.c       Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_166.c       Sun May 16 11:11:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_166.c,v 1.2 2021/01/31 13:11:08 rillig Exp $       */
+/*     $NetBSD: msg_166.c,v 1.3 2021/05/16 11:11:37 rillig Exp $       */
 # 3 "msg_166.c"
 
 // Test for message: precision lost in bit-field assignment [166]
@@ -22,8 +22,8 @@ struct bit_set {
         * https://bugs.llvm.org/show_bug.cgi?id=11272.
         */
 
-       int minus_1_to_0: 1;            /* expect: 34 */
-       int minus_8_to_7: 4;            /* expect: 34 */
+       int minus_1_to_0: 1;            /* expect: 344 */
+       int minus_8_to_7: 4;            /* expect: 344 */
        unsigned zero_to_1: 1;
        unsigned zero_to_15: 4;
 };
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_166.exp
--- a/tests/usr.bin/xlint/lint1/msg_166.exp     Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_166.exp     Sun May 16 11:11:36 2021 +0000
@@ -1,5 +1,5 @@
-msg_166.c(25): warning: nonportable bit-field type 'int' [34]
-msg_166.c(26): warning: nonportable bit-field type 'int' [34]
+msg_166.c(25): warning: bit-field of type plain 'int' has implementation-defined signedness [344]
+msg_166.c(26): warning: bit-field of type plain 'int' has implementation-defined signedness [344]
 msg_166.c(35): warning: precision lost in bit-field assignment [166]
 msg_166.c(38): warning: precision lost in bit-field assignment [166]
 msg_166.c(39): warning: precision lost in bit-field assignment [166]
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_344.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_344.c       Sun May 16 11:11:36 2021 +0000
@@ -0,0 +1,24 @@
+/*     $NetBSD: msg_344.c,v 1.1 2021/05/16 11:11:37 rillig Exp $       */
+# 3 "msg_344.c"
+
+// Test for message: bit-field of type plain 'int' has implementation-defined signedness [344]
+
+/* lint1-extra-flags: -p */
+
+/*
+ * C90 3.5.2.1 allows 'int', 'signed int', 'unsigned int' as bit-field types.
+ *
+ * C99 6.7.2.1 significantly changed the wording of the allowable types for
+ * bit-fields.  For example, 6.7.2.1p4 does not mention plain 'int' at all.
+ * The rationale for C99 6.7.2.1 mentions plain 'int' though, and it would
+ * have broken a lot of existing code to disallow plain 'int' as a bit-field
+ * type.  Footnote 104 explicitly mentions plain 'int' as well and it even
+ * allows typedef-types for bit-fields.
+ */
+struct example {
+       /* expect+1: 344 */
+       int plain_int: 1;
+
+       signed int signed_int: 1;
+       unsigned int unsigned_int: 1;
+};
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/msg_344.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_344.exp     Sun May 16 11:11:36 2021 +0000
@@ -0,0 +1,1 @@
+msg_344.c(20): warning: bit-field of type plain 'int' has implementation-defined signedness [344]
diff -r 10efba0c60e8 -r 5d257f9a1f6e tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sun May 16 10:34:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sun May 16 11:11:36 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.49 2021/05/14 21:14:55 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.50 2021/05/16 11:11:37 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -194,7 +194,7 @@ all_messages_body()
 
        failed=""
 
-       for msg in $(seq 0 343); do
+       for msg in $(seq 0 344); do
                name="$(printf 'msg_%03d.c' "${msg}")"
                check_lint1 "${name}" \
                || failed="$failed${failed:+ }$name"
diff -r 10efba0c60e8 -r 5d257f9a1f6e usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun May 16 10:34:19 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun May 16 11:11:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.181 2021/05/16 10:34:19 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.182 2021/05/16 11:11:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.181 2021/05/16 10:34:19 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.182 2021/05/16 11:11:36 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1112,8 +1112,8 @@ check_bit_field_type(sym_t *dsym,  type_
                }
        } else if (t == INT && dcs->d_sign_mod == NOTSPEC) {
                if (pflag && !bitfieldtype_ok) {
-                       /* nonportable bit-field type '%s' */
-                       warning(34, type_name(tp));
+                       /* bit-field of type plain 'int' has ... */
+                       warning(344);
                }
        } else if (t != INT && t != UINT && t != BOOL) {
                /*
diff -r 10efba0c60e8 -r 5d257f9a1f6e usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun May 16 10:34:19 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun May 16 11:11:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.118 2021/05/16 10:34:19 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.119 2021/05/16 11:11:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.118 2021/05/16 10:34:19 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.119 2021/05/16 11:11:36 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -398,6 +398,7 @@ const char *const msgs[] = {
        "argument to '%s' must be 'unsigned char' or EOF, not '%s'",  /* 341 */
        "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */
        "static array size is a C11 extension",                       /* 343 */
+       "bit-field of type plain 'int' has implementation-defined signedness", /* 344 */
 };
 
 static struct include_level {



Home | Main Index | Thread Index | Old Index