Sat Jan 2 16:33:39 2021 UTC ()
lint: allow _Bool for bit-fields


(rillig)
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_035.c
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_035.exp
diff -r1.98 -r1.99 src/usr.bin/xlint/lint1/decl.c

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_035.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_035.c 2021/01/02 16:12:39 1.3
+++ src/tests/usr.bin/xlint/lint1/msg_035.c 2021/01/02 16:33:39 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: msg_035.c,v 1.3 2021/01/02 16:12:39 rillig Exp $ */ 1/* $NetBSD: msg_035.c,v 1.4 2021/01/02 16:33:39 rillig Exp $ */
2# 3 "msg_035.c" 2# 3 "msg_035.c"
3 3
4// Test for message: illegal bit-field type [35] 4// Test for message: illegal bit-field type [35]
5 5
6/* 6/*
7 * In traditional C, only unsigned int is a portable bit-field type. 7 * In traditional C, only unsigned int is a portable bit-field type.
8 * 8 *
9 * In C89, only int, signed int and unsigned int are allowed (3.5.2.1p7). 9 * In C89, only int, signed int and unsigned int are allowed (3.5.2.1p7).
10 * 10 *
11 * In C99 and C11, only _Bool, signed int and unsigned int are allowed, 11 * In C99 and C11, only _Bool, signed int and unsigned int are allowed,
12 * plus implementation-defined types (6.7.2.1p5). 12 * plus implementation-defined types (6.7.2.1p5).
13 */ 13 */
14 14
@@ -20,27 +20,27 @@ typedef union { @@ -20,27 +20,27 @@ typedef union {
20 int dummy; 20 int dummy;
21} example_union; 21} example_union;
22 22
23typedef enum { 23typedef enum {
24 NO, YES 24 NO, YES
25} example_enum; 25} example_enum;
26 26
27typedef void (example_function)(int, const char *); 27typedef void (example_function)(int, const char *);
28 28
29/* Try all types from tspec_t. */ 29/* Try all types from tspec_t. */
30struct example { 30struct example {
31 signed signed_flag: 1; 31 signed signed_flag: 1;
32 unsigned unsigned_flag: 1; 32 unsigned unsigned_flag: 1;
33 _Bool boolean_flag: 1; // FIXME: allowed since C99 6.7.2.1p5 33 _Bool boolean_flag: 1;
34 char char_flag: 1; 34 char char_flag: 1;
35 signed char signed_char_flag: 1; 35 signed char signed_char_flag: 1;
36 unsigned char unsigned_char_flag: 1; 36 unsigned char unsigned_char_flag: 1;
37 short short_flag: 1; 37 short short_flag: 1;
38 unsigned short unsigned_short_flag: 1; 38 unsigned short unsigned_short_flag: 1;
39 int int_flag: 1; 39 int int_flag: 1;
40 unsigned int unsigned_int_flag: 1; 40 unsigned int unsigned_int_flag: 1;
41 long long_flag: 1; 41 long long_flag: 1;
42 unsigned long unsigned_long_flag: 1; 42 unsigned long unsigned_long_flag: 1;
43 long long long_long_flag: 1; 43 long long long_long_flag: 1;
44 unsigned long long unsigned_long_long_flag: 1; 44 unsigned long long unsigned_long_long_flag: 1;
45 /* __int128_t omitted since it is not always defined */ 45 /* __int128_t omitted since it is not always defined */
46 /* __uint128_t omitted since it is not always defined */ 46 /* __uint128_t omitted since it is not always defined */

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/Attic/msg_035.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/msg_035.exp 2021/01/02 16:12:39 1.3
+++ src/tests/usr.bin/xlint/lint1/Attic/msg_035.exp 2021/01/02 16:33:39 1.4
@@ -1,14 +1,13 @@ @@ -1,14 +1,13 @@
1msg_035.c(33): warning: illegal bit-field type [35] 
2msg_035.c(41): warning: illegal bit-field type [35] 1msg_035.c(41): warning: illegal bit-field type [35]
3msg_035.c(42): warning: illegal bit-field type [35] 2msg_035.c(42): warning: illegal bit-field type [35]
4msg_035.c(43): warning: illegal bit-field type [35] 3msg_035.c(43): warning: illegal bit-field type [35]
5msg_035.c(44): warning: illegal bit-field type [35] 4msg_035.c(44): warning: illegal bit-field type [35]
6msg_035.c(47): warning: illegal bit-field type [35] 5msg_035.c(47): warning: illegal bit-field type [35]
7msg_035.c(48): warning: illegal bit-field type [35] 6msg_035.c(48): warning: illegal bit-field type [35]
8msg_035.c(49): warning: illegal bit-field type [35] 7msg_035.c(49): warning: illegal bit-field type [35]
9msg_035.c(50): void type for void_flag [19] 8msg_035.c(50): void type for void_flag [19]
10msg_035.c(50): zero size bit-field [37] 9msg_035.c(50): zero size bit-field [37]
11msg_035.c(51): warning: illegal bit-field type [35] 10msg_035.c(51): warning: illegal bit-field type [35]
12msg_035.c(52): warning: illegal bit-field type [35] 11msg_035.c(52): warning: illegal bit-field type [35]
13msg_035.c(54): warning: illegal bit-field type [35] 12msg_035.c(54): warning: illegal bit-field type [35]
14msg_035.c(55): warning: illegal bit-field type [35] 13msg_035.c(55): warning: illegal bit-field type [35]

cvs diff -r1.98 -r1.99 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2021/01/02 03:49:25 1.98
+++ src/usr.bin/xlint/lint1/decl.c 2021/01/02 16:33:39 1.99
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.98 2021/01/02 03:49:25 rillig Exp $ */ 1/* $NetBSD: decl.c,v 1.99 2021/01/02 16:33:39 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: decl.c,v 1.98 2021/01/02 03:49:25 rillig Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.99 2021/01/02 16:33:39 rillig Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmtic types and void */ 53/* shared type structures for arithmtic types and void */
54static type_t *typetab; 54static type_t *typetab;
@@ -1108,27 +1108,27 @@ declarator_1_struct_union(sym_t *dsym) @@ -1108,27 +1108,27 @@ declarator_1_struct_union(sym_t *dsym)
1108 if (sflag) { 1108 if (sflag) {
1109 /* bit-field type '%s' invalid ... */ 1109 /* bit-field type '%s' invalid ... */
1110 warning(273, type_name(tp)); 1110 warning(273, type_name(tp));
1111 } else if (pflag) { 1111 } else if (pflag) {
1112 /* nonportable bit-field type */ 1112 /* nonportable bit-field type */
1113 warning(34); 1113 warning(34);
1114 } 1114 }
1115 } 1115 }
1116 } else if (t == INT && dcs->d_smod == NOTSPEC) { 1116 } else if (t == INT && dcs->d_smod == NOTSPEC) {
1117 if (pflag && bitfieldtype_ok == 0) { 1117 if (pflag && bitfieldtype_ok == 0) {
1118 /* nonportable bit-field type */ 1118 /* nonportable bit-field type */
1119 warning(34); 1119 warning(34);
1120 } 1120 }
1121 } else if (t != INT && t != UINT) { 1121 } else if (t != INT && t != UINT && t != BOOL) {
1122 /* 1122 /*
1123 * Non-integer types are always illegal for 1123 * Non-integer types are always illegal for
1124 * bitfields, regardless of BITFIELDTYPE. 1124 * bitfields, regardless of BITFIELDTYPE.
1125 * Integer types not dealt with above are 1125 * Integer types not dealt with above are
1126 * okay only if BITFIELDTYPE is in effect. 1126 * okay only if BITFIELDTYPE is in effect.
1127 */ 1127 */
1128 if (bitfieldtype_ok == 0 || tspec_is_int(t) == 0) { 1128 if (bitfieldtype_ok == 0 || tspec_is_int(t) == 0) {
1129 /* illegal bit-field type */ 1129 /* illegal bit-field type */
1130 warning(35); 1130 warning(35);
1131 sz = tp->t_flen; 1131 sz = tp->t_flen;
1132 dsym->s_type = tp = duptyp(gettyp(t = INT)); 1132 dsym->s_type = tp = duptyp(gettyp(t = INT));
1133 if ((tp->t_flen = sz) > size(t)) 1133 if ((tp->t_flen = sz) > size(t))
1134 tp->t_flen = size(t); 1134 tp->t_flen = size(t);