Module Name:    src
Committed By:   rillig
Date:           Sun May  2 22:07:49 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: gcc_bit_field_types.c
            gcc_bit_field_types.exp
        src/usr.bin/xlint/lint1: decl.c

Log Message:
lint: allow large integer types for bit-fields in GCC mode

These types are explicitly allowed by GCC.

I'm not sure which of the flags -g and -p should be stronger.  That is,
if both -g and -p are given, should 'unsigned char' be allowed as a
bit-field type since -g would allow it, or should it be warned about
since -p warns about it?  For now, continue to warn about these.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c \
    src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/decl.c

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/gcc_bit_field_types.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.2	Sun May  2 21:47:28 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c	Sun May  2 22:07:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_bit_field_types.c,v 1.2 2021/05/02 21:47:28 rillig Exp $	*/
+/*	$NetBSD: gcc_bit_field_types.c,v 1.3 2021/05/02 22:07:49 rillig Exp $	*/
 # 3 "gcc_bit_field_types.c"
 
 /*
@@ -13,9 +13,9 @@
 struct example {
 	int int_flag: 1;
 	unsigned int unsigned_int_flag: 1;
-	long long_flag: 1;	/* expect: 35 *//*FIXME*/
-	unsigned long unsigned_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	long long long_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	unsigned long long unsigned_long_long_flag: 1;	/* expect: 35 *//*FIXME*/
-	double double_flag: 1;	/* expect: 35 */
+	long long_flag: 1;
+	unsigned long unsigned_long_flag: 1;
+	long long long_long_flag: 1;
+	unsigned long long unsigned_long_long_flag: 1;
+	double double_flag: 1;	/* expect: illegal bit-field type 'double' */
 };
Index: src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp:1.2	Sun May  2 21:47:28 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp	Sun May  2 22:07:49 2021
@@ -1,5 +1 @@
-gcc_bit_field_types.c(16): warning: illegal bit-field type 'long' [35]
-gcc_bit_field_types.c(17): warning: illegal bit-field type 'unsigned long' [35]
-gcc_bit_field_types.c(18): warning: illegal bit-field type 'long long' [35]
-gcc_bit_field_types.c(19): warning: illegal bit-field type 'unsigned long long' [35]
 gcc_bit_field_types.c(20): warning: illegal bit-field type 'double' [35]

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.179 src/usr.bin/xlint/lint1/decl.c:1.180
--- src/usr.bin/xlint/lint1/decl.c:1.179	Sun May  2 21:48:53 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun May  2 22:07:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.179 2021/05/02 21:48:53 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.180 2021/05/02 22:07:49 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.179 2021/05/02 21:48:53 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.180 2021/05/02 22:07:49 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1121,7 +1121,7 @@ check_bit_field_type(sym_t *dsym,  type_
 		 * regardless of BITFIELDTYPE. Integer types not dealt with
 		 * above are okay only if BITFIELDTYPE is in effect.
 		 */
-		if (!bitfieldtype_ok || !is_integer(t)) {
+		if (!(bitfieldtype_ok || gflag) || !is_integer(t)) {
 			/* illegal bit-field type '%s' */
 			warning(35, type_name(tp));
 			int sz = tp->t_flen;

Reply via email to