Module Name:    src
Committed By:   rillig
Date:           Sun Jan 17 13:50:33 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
            d_c99_bool_strict.exp
        src/usr.bin/xlint/common: inittyp.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: in strict bool mode, don't treat bool as arithmetic type


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.12 -r1.13 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/xlint/common/inittyp.c
cvs rdiff -u -r1.164 -r1.165 src/usr.bin/xlint/lint1/tree.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/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.14 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.15
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.14	Sun Jan 17 13:15:03 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sun Jan 17 13:50:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.14 2021/01/17 13:15:03 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.15 2021/01/17 13:50:33 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -167,19 +167,19 @@ enum strict_bool_constant_expressions {
 	 */
 	Q2 = (13 > 12 ? 1 : 7) ? 100 : 101,	/* expect: 331 */
 
-	BINAND_BOOL = __lint_false & __lint_true,
+	BINAND_BOOL = __lint_false & __lint_true, /* expect: 55 */
 	BINAND_INT = 0 & 1,
 
-	BINXOR_BOOL = __lint_false ^ __lint_true,
+	BINXOR_BOOL = __lint_false ^ __lint_true, /* expect: 55 */
 	BINXOR_INT = 0 ^ 1,
 
-	BINOR_BOOL = __lint_false | __lint_true,
+	BINOR_BOOL = __lint_false | __lint_true, /* expect: 55 */
 	BINOR_INT = 0 | 1,
 
-	LOGOR_BOOL = __lint_false || __lint_true,
+	LOGOR_BOOL = __lint_false || __lint_true, /* expect: 55 */
 	LOGOR_INT = 0 || 1,	/* expect: 331, 332 */
 
-	LOGAND_BOOL = __lint_false && __lint_true,
+	LOGAND_BOOL = __lint_false && __lint_true, /* expect: 55 */
 	LOGAND_INT = 0 && 1,	/* expect: 331, 332 */
 };
 
@@ -221,7 +221,7 @@ strict_bool_bit_fields_operand_conversio
 	struct s s = { 0 };
 
 	s.ordinary = s.ordinary | s.ordinary;
-	s.bit_field = s.bit_field | s.bit_field; /* FIXME *//* expect: 107 */
+	s.bit_field = s.bit_field | s.bit_field;
 }
 
 /*
@@ -716,27 +716,6 @@ strict_bool_operator_eq_bool_int(void)
 	(void)(strict_bool_conversion_return_false() == 0); /* expect: 107 */
 }
 
-/*
- * When building the NE node, the following steps happen:
- *
- * ln is promoted from BOOL:1 to INT:1 since it is a bit field and C90 says
- * that bit fields must always be promoted to int.
- *
- * rn is promoted from BOOL.  promote() does not handle BOOL explicitly,
- * therefore it is kept as-is.  That may or may not have been an oversight
- * in the initial implementation of supporting BOOL.
- *
- * After that, the two nodes are balanced.  At this point, their types are
- * INT:1 and BOOL.  INT is considered the larger of the two types, even
- * though it is a bit field in this case.  Therefore BOOL is converted to
- * INT now, and since it is a constant, the converted node loses all
- * information about its previous type.
- *
- * During these conversions and promotions, the code asks whether BOOL
- * is an arithmetic type.  If that isn't the case, no conversion or
- * promotion takes place.  Since strict bool mode explicitly treats BOOL
- * as non-arithmetic, changing is_arithmetic sounds like the way to go.
- */
 void
 strict_bool_assign_bit_field_then_compare(void)
 {
@@ -746,6 +725,5 @@ strict_bool_assign_bit_field_then_compar
 
 	struct s s = { __lint_false };
 
-	/* FIXME: The __lint_false is converted irreversibly to an INT. */
-	(void)((s.flag = s.flag) != __lint_false); /* expect: 107 */
+	(void)((s.flag = s.flag) != __lint_false);
 }

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.12 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.13
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.12	Sun Jan 17 13:15:03 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp	Sun Jan 17 13:50:33 2021
@@ -8,15 +8,19 @@ d_c99_bool_strict.c(148): left operand o
 d_c99_bool_strict.c(158): left operand of '?' must be bool, not 'int' [331]
 d_c99_bool_strict.c(159): left operand of '?' must be bool, not 'int' [331]
 d_c99_bool_strict.c(168): left operand of '?' must be bool, not 'int' [331]
+d_c99_bool_strict.c(170): integral constant expression expected [55]
+d_c99_bool_strict.c(173): integral constant expression expected [55]
+d_c99_bool_strict.c(176): integral constant expression expected [55]
+d_c99_bool_strict.c(179): integral constant expression expected [55]
 d_c99_bool_strict.c(180): left operand of '||' must be bool, not 'int' [331]
 d_c99_bool_strict.c(180): right operand of '||' must be bool, not 'int' [332]
+d_c99_bool_strict.c(182): integral constant expression expected [55]
 d_c99_bool_strict.c(183): left operand of '&&' must be bool, not 'int' [331]
 d_c99_bool_strict.c(183): right operand of '&&' must be bool, not 'int' [332]
 d_c99_bool_strict.c(203): operands of '=' have incompatible types (_Bool != unsigned int) [107]
 d_c99_bool_strict.c(205): operands of '=' have incompatible types (unsigned int != _Bool) [107]
 d_c99_bool_strict.c(208): operands of '=' have incompatible types (_Bool != unsigned int) [107]
 d_c99_bool_strict.c(210): operands of '=' have incompatible types (unsigned int != _Bool) [107]
-d_c99_bool_strict.c(224): operands of '=' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(252): return value type mismatch (_Bool) and (int) [211]
 d_c99_bool_strict.c(258): return value type mismatch (_Bool) and (int) [211]
 d_c99_bool_strict.c(264): return value type mismatch (_Bool) and (int) [211]
@@ -142,4 +146,3 @@ d_c99_bool_strict.c(670): operands of '=
 d_c99_bool_strict.c(677): operands of '=' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(652): warning: argument flags unused in function strict_bool_bitwise_and_enum [231]
 d_c99_bool_strict.c(716): operands of '==' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(750): operands of '!=' have incompatible types (_Bool != int) [107]

Index: src/usr.bin/xlint/common/inittyp.c
diff -u src/usr.bin/xlint/common/inittyp.c:1.16 src/usr.bin/xlint/common/inittyp.c:1.17
--- src/usr.bin/xlint/common/inittyp.c:1.16	Sat Jan  9 14:10:15 2021
+++ src/usr.bin/xlint/common/inittyp.c	Sun Jan 17 13:50:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inittyp.c,v 1.16 2021/01/09 14:10:15 rillig Exp $	*/
+/*	$NetBSD: inittyp.c,v 1.17 2021/01/17 13:50:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: inittyp.c,v 1.16 2021/01/09 14:10:15 rillig Exp $");
+__RCSID("$NetBSD: inittyp.c,v 1.17 2021/01/17 13:50:32 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -164,4 +164,9 @@ inittyp(void)
 		for (i = 0; i < NTSPEC; i++)
 			ttab[i].tt_psz = ttab[i].tt_sz;
 	}
+	if (Tflag) {
+		ttab[BOOL].tt_is_integer = false;
+		ttab[BOOL].tt_is_uinteger = false;
+		ttab[BOOL].tt_is_arithmetic = false;
+	}
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.164 src/usr.bin/xlint/lint1/tree.c:1.165
--- src/usr.bin/xlint/lint1/tree.c:1.164	Sun Jan 17 12:23:01 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Jan 17 13:50:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.164 2021/01/17 12:23:01 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.165 2021/01/17 13:50:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.164 2021/01/17 12:23:01 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.165 2021/01/17 13:50:32 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1000,6 +1000,8 @@ typeok_colon(const mod_t *mp,
 
 	if (is_arithmetic(lt) && is_arithmetic(rt))
 		return true;
+	if (lt == BOOL && rt == BOOL)
+		return true;
 
 	if (lt == STRUCT && rt == STRUCT && ltp->t_str == rtp->t_str)
 		return true;
@@ -1208,6 +1210,8 @@ typeok_scalar(op_t op, const mod_t *mp,
 	      const tnode_t *ln, tspec_t lt,
 	      const tnode_t *rn, tspec_t rt)
 {
+	if (mp->m_takes_bool && lt == BOOL && rt == BOOL)
+		return true;
 	if (mp->m_requires_integer) {
 		if (!is_integer(lt) || (mp->m_binary && !is_integer(rt))) {
 			warn_incompatible_types(op, lt, rt);
@@ -2808,6 +2812,8 @@ build_colon(tnode_t *ln, tnode_t *rn)
 	 */
 	if (is_arithmetic(lt) && is_arithmetic(rt)) {
 		rtp = ln->tn_type;
+	} else if (lt == BOOL && rt == BOOL) {
+		rtp = ln->tn_type;
 	} else if (lt == VOID || rt == VOID) {
 		rtp = gettyp(VOID);
 	} else if (lt == STRUCT || lt == UNION) {

Reply via email to