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: in strict bool mode, don't treat b...



details:   https://anonhg.NetBSD.org/src/rev/234dd97fbb9c
branches:  trunk
changeset: 979927:234dd97fbb9c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 17 13:50:32 2021 +0000

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

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |  38 +++++-------------------
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   7 +++-
 usr.bin/xlint/common/inittyp.c                  |   9 ++++-
 usr.bin/xlint/lint1/tree.c                      |  10 +++++-
 4 files changed, 28 insertions(+), 36 deletions(-)

diffs (181 lines):

diff -r eef43880206e -r 234dd97fbb9c tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Jan 17 13:15:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Jan 17 13:50:32 2021 +0000
@@ -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 @@
         */
        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 @@
        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 @@
        (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 @@
 
        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);
 }
diff -r eef43880206e -r 234dd97fbb9c tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Jan 17 13:15:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Jan 17 13:50:32 2021 +0000
@@ -8,15 +8,19 @@
 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(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]
diff -r eef43880206e -r 234dd97fbb9c usr.bin/xlint/common/inittyp.c
--- a/usr.bin/xlint/common/inittyp.c    Sun Jan 17 13:15:03 2021 +0000
+++ b/usr.bin/xlint/common/inittyp.c    Sun Jan 17 13:50:32 2021 +0000
@@ -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 @@
                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;
+       }
 }
diff -r eef43880206e -r 234dd97fbb9c usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jan 17 13:15:03 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jan 17 13:50:32 2021 +0000
@@ -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 @@
 
        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 @@
              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 @@
         */
        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) {



Home | Main Index | Thread Index | Old Index