Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/xlint lint: in strict bool mode, integer const...
details: https://anonhg.NetBSD.org/src/rev/735617a3507c
branches: trunk
changeset: 949770:735617a3507c
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 16 16:03:46 2021 +0000
description:
lint: in strict bool mode, integer constants do not have type bool
Previously, lint1 allowed integer constants such as 0 and 1 to be used
as bool constants. This was only half-baked since after fixing all
error messages from that strict mode, there may still be integer
literals in the code that should be replaced with true or false. This
would stop a migration from int to bool in the middle, leaving
inconsistent code around.
To find the remaining type inconsistencies, treat integers and bool as
completely incompatible, even for compile time constants.
diffstat:
distrib/sets/lists/comp/mi | 4 +-
tests/usr.bin/xlint/lint1/d_c99_bool_strict.c | 56 ++++++++++++------------
tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp | 30 ++++++++++++-
tests/usr.bin/xlint/lint1/msg_330.c | 6 +-
tests/usr.bin/xlint/lint1/msg_330.exp | 2 +
tests/usr.bin/xlint/lint1/msg_331.c | 6 +-
tests/usr.bin/xlint/lint1/msg_331.exp | 2 +
tests/usr.bin/xlint/lint1/msg_332.c | 6 +-
tests/usr.bin/xlint/lint1/msg_332.exp | 2 +
tests/usr.bin/xlint/lint1/msg_333.c | 8 ++-
tests/usr.bin/xlint/lint1/msg_333.exp | 1 +
tests/usr.bin/xlint/lint1/msg_336.c | 4 +-
tests/usr.bin/xlint/lint1/msg_336.exp | 1 +
tests/usr.bin/xlint/lint1/msg_337.c | 4 +-
tests/usr.bin/xlint/lint1/msg_337.exp | 1 +
usr.bin/xlint/lint1/cgram.y | 6 +-
usr.bin/xlint/lint1/decl.c | 14 +++---
usr.bin/xlint/lint1/lint1.h | 8 +-
usr.bin/xlint/lint1/tree.c | 31 ++-----------
usr.bin/xlint/xlint/Makefile | 6 ++-
usr.bin/xlint/xlint/pathnames.h | 5 +-
usr.bin/xlint/xlint/strict-bool-stdbool.h | 41 ++++++++++++++++++
usr.bin/xlint/xlint/xlint.c | 12 ++++-
23 files changed, 165 insertions(+), 91 deletions(-)
diffs (truncated from 742 to 300 lines):
diff -r bdd9cd337356 -r 735617a3507c distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Sat Jan 16 15:35:28 2021 +0000
+++ b/distrib/sets/lists/comp/mi Sat Jan 16 16:03:46 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.2368 2021/01/08 09:41:24 uki Exp $
+# $NetBSD: mi,v 1.2369 2021/01/16 16:03:46 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@@ -4011,6 +4011,8 @@
./usr/libdata/debug/usr/tests/crypto/libcrypto/h_shatest.debug comp-obsolete openssl=11,obsolete
./usr/libdata/debug/usr/tests/crypto/libcrypto/h_x509v3test.debug comp-obsolete openssl=11,obsolete
./usr/libdata/ldscripts/kmodule comp-util-share binutils,kmod
+./usr/libdata/lint/strict-bool comp-c-bin lint
+./usr/libdata/lint/strict-bool/stdbool.h comp-c-bin lint
./usr/libdata/lint/llib-larchive.ln comp-c-lintlib lint
./usr/libdata/lint/llib-lasn1.ln comp-krb5-lintlib lint,kerberos
./usr/libdata/lint/llib-lbind9.ln comp-bind-lintlib lint
diff -r bdd9cd337356 -r 735617a3507c tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sat Jan 16 15:35:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sat Jan 16 16:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_bool_strict.c,v 1.8 2021/01/16 15:02:11 rillig Exp $ */
+/* $NetBSD: d_c99_bool_strict.c,v 1.9 2021/01/16 16:03:47 rillig Exp $ */
# 3 "d_c99_bool_strict.c"
/*
@@ -123,8 +123,8 @@
{
accept_bool(__lint_false);
accept_bool(__lint_true);
- accept_bool(0); /* TODO: expect: 334 */
- accept_bool(1); /* TODO: expect: 334 */
+ accept_bool(0); /* expect: 334 */
+ accept_bool(1); /* expect: 334 */
accept_bool(2); /* expect: 334 */
}
@@ -136,16 +136,16 @@
TRUE = __lint_true ? 100 : 101,
/* Not ok: an integer is not a boolean constant expression. */
- INT0 = 0 ? 100 : 101, /* TODO: expect: 331 */
+ INT0 = 0 ? 100 : 101, /* expect: 331 */
/* Not ok: an integer is not a boolean constant expression. */
- INT1 = 1 ? 100 : 101, /* TODO: expect: 331 */
+ INT1 = 1 ? 100 : 101, /* expect: 331 */
/* Not ok: 2 is not a boolean constant. */
INT2 = 2 ? 100 : 101, /* expect: 331 */
/* Not ok: compound integer expressions are not bool. */
- ARITH = (2 - 2) ? 100 : 101, /* TODO: expect: 331 */
+ ARITH = (2 - 2) ? 100 : 101, /* expect: 331 */
/*
* Without strict bool mode, these two variants of an expression can
@@ -155,8 +155,8 @@
* TODO: figure out an elegant way to achieve the same effect in
* strict bool mode.
*/
- BINARY_PLUS = (1 + 0) ? 100 : 101, /* TODO: expect: 331 */
- UNARY_PLUS = (+0) ? 100 : 101, /* TODO: expect: 331 */
+ BINARY_PLUS = (1 + 0) ? 100 : 101, /* expect: 331 */
+ UNARY_PLUS = (+0) ? 100 : 101, /* expect: 331 */
/* The main operator '>' has return type bool. */
Q1 = (13 > 12) ? 100 : 101,
@@ -165,7 +165,7 @@
* The parenthesized expression has type int and thus cannot be
* used as the controlling expression in the '?:' operator.
*/
- Q2 = (13 > 12 ? 1 : 7) ? 100 : 101,
+ Q2 = (13 > 12 ? 1 : 7) ? 100 : 101, /* expect: 331 */
BINAND_BOOL = __lint_false & __lint_true,
BINAND_INT = 0 & 1,
@@ -177,10 +177,10 @@
BINOR_INT = 0 | 1,
LOGOR_BOOL = __lint_false || __lint_true,
- LOGOR_INT = 0 || 1, /* TODO: expect: 331, 332 */
+ LOGOR_INT = 0 || 1, /* expect: 331, 332 */
LOGAND_BOOL = __lint_false && __lint_true,
- LOGAND_INT = 0 && 1, /* TODO: expect: 331, 332 */
+ LOGAND_INT = 0 && 1, /* expect: 331, 332 */
};
/*
@@ -249,13 +249,13 @@
bool
strict_bool_conversion_return_0(void)
{
- return 0; /* TODO: expect: 211 */
+ return 0; /* expect: 211 */
}
bool
strict_bool_conversion_return_1(void)
{
- return 1; /* TODO: expect: 211 */
+ return 1; /* expect: 211 */
}
bool
@@ -315,8 +315,8 @@
take_arguments(__lint_true, i, p);
/* Trying to pass integer constants. */
- take_arguments(0, i, p); /* TODO: expect: 334 */
- take_arguments(1, i, p); /* TODO: expect: 334 */
+ take_arguments(0, i, p); /* expect: 334 */
+ take_arguments(1, i, p); /* expect: 334 */
take_arguments(2, i, p); /* expect: 334 */
}
@@ -326,9 +326,9 @@
bool b;
int i;
- b = 0;
- b = __lint_false; /* TODO: expect: 107 */
- b = 1;
+ b = 0; /* expect: 107 */
+ b = __lint_false;
+ b = 1; /* expect: 107 */
b = __lint_true;
i = 0;
@@ -372,10 +372,10 @@
if (b)
do_nothing();
- if (0) /* TODO: expect: 333 */
+ if (0) /* expect: 333 */
do_nothing();
- if (1) /* TODO: expect: 333 */
+ if (1) /* expect: 333 */
do_nothing();
if (2) /* expect: 333 */
@@ -422,8 +422,8 @@
i = !i; /* expect: 330 */
i = !!!i; /* expect: 330 */
- i = !0; /* expect: 107 */
- i = !1; /* expect: 107 */
+ i = !0; /* expect: 330 */
+ i = !1; /* expect: 330 */
}
void
@@ -476,13 +476,13 @@
struct bool_struct bs = { __lint_true };
b = bs.b;
bs.b = b;
- bs.b = 0; /* TODO: expect: incompatible types */
+ bs.b = 0; /* expect: 107 */
/* Access a struct member using the '->' operator. */
struct bool_struct *bsp = &bs;
b = bsp->b;
bsp->b = b;
- bsp->b = 0;
+ bsp->b = 0; /* expect: 107 */
}
int
@@ -502,10 +502,10 @@
b = i && i; /* expect: 331, 332 */
b = i || i; /* expect: 331, 332 */
- b = b && 0;
- b = 0 && b;
- b = b || 0;
- b = 0 || b;
+ b = b && 0; /* expect: 332 */
+ b = 0 && b; /* expect: 331 */
+ b = b || 0; /* expect: 332 */
+ b = 0 || b; /* expect: 331 */
return i;
}
diff -r bdd9cd337356 -r 735617a3507c tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sat Jan 16 15:35:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sat Jan 16 16:03:46 2021 +0000
@@ -1,10 +1,24 @@
+d_c99_bool_strict.c(126): argument #1 expects '_Bool', gets passed 'int' [334]
+d_c99_bool_strict.c(127): argument #1 expects '_Bool', gets passed 'int' [334]
d_c99_bool_strict.c(128): argument #1 expects '_Bool', gets passed 'int' [334]
+d_c99_bool_strict.c(139): left operand of '?' must be bool, not 'int' [331]
+d_c99_bool_strict.c(142): left operand of '?' must be bool, not 'int' [331]
d_c99_bool_strict.c(145): left operand of '?' must be bool, not 'int' [331]
+d_c99_bool_strict.c(148): left operand of '?' must be bool, not 'int' [331]
+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(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(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]
d_c99_bool_strict.c(270): return value type mismatch (_Bool) and (pointer to const void) [211]
d_c99_bool_strict.c(268): warning: argument p unused in function strict_bool_conversion_return_pointer [231]
@@ -16,7 +30,11 @@
d_c99_bool_strict.c(303): warning: illegal combination of pointer (pointer to const char) and integer (int), arg #3 [154]
d_c99_bool_strict.c(306): argument #1 expects '_Bool', gets passed 'pointer' [334]
d_c99_bool_strict.c(306): warning: illegal combination of integer (int) and pointer (pointer to const char), arg #2 [154]
+d_c99_bool_strict.c(318): argument #1 expects '_Bool', gets passed 'int' [334]
+d_c99_bool_strict.c(319): argument #1 expects '_Bool', gets passed 'int' [334]
d_c99_bool_strict.c(320): argument #1 expects '_Bool', gets passed 'int' [334]
+d_c99_bool_strict.c(329): operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(331): operands of '=' have incompatible types (_Bool != int) [107]
d_c99_bool_strict.c(335): operands of '=' have incompatible types (int != _Bool) [107]
d_c99_bool_strict.c(337): operands of '=' have incompatible types (int != _Bool) [107]
d_c99_bool_strict.c(339): operands of '=' have incompatible types (int != _Bool) [107]
@@ -26,19 +44,27 @@
d_c99_bool_strict.c(353): operands of '=' have incompatible types (double != _Bool) [107]
d_c99_bool_strict.c(354): operands of '=' have incompatible types (pointer != _Bool) [107]
d_c99_bool_strict.c(344): warning: argument b unused in function strict_bool_conversion_from_bool_to_scalar [231]
+d_c99_bool_strict.c(375): controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict.c(378): controlling expression must be bool, not 'int' [333]
d_c99_bool_strict.c(381): controlling expression must be bool, not 'int' [333]
d_c99_bool_strict.c(385): controlling expression must be bool, not 'int' [333]
d_c99_bool_strict.c(391): controlling expression must be bool, not 'double' [333]
d_c99_bool_strict.c(397): controlling expression must be bool, not 'pointer' [333]
d_c99_bool_strict.c(423): operand of '!' must be bool, not 'int' [330]
d_c99_bool_strict.c(424): operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict.c(425): operands of '=' have incompatible types (int != _Bool) [107]
-d_c99_bool_strict.c(426): operands of '=' have incompatible types (int != _Bool) [107]
+d_c99_bool_strict.c(425): operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict.c(426): operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict.c(479): operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(485): operands of '=' have incompatible types (_Bool != int) [107]
d_c99_bool_strict.c(501): operand of '!' must be bool, not 'int' [330]
d_c99_bool_strict.c(502): left operand of '&&' must be bool, not 'int' [331]
d_c99_bool_strict.c(502): right operand of '&&' must be bool, not 'int' [332]
d_c99_bool_strict.c(503): left operand of '||' must be bool, not 'int' [331]
d_c99_bool_strict.c(503): right operand of '||' must be bool, not 'int' [332]
+d_c99_bool_strict.c(505): right operand of '&&' must be bool, not 'int' [332]
+d_c99_bool_strict.c(506): left operand of '&&' must be bool, not 'int' [331]
+d_c99_bool_strict.c(507): right operand of '||' must be bool, not 'int' [332]
+d_c99_bool_strict.c(508): left operand of '||' must be bool, not 'int' [331]
d_c99_bool_strict.c(517): operand of '~' must not be bool [335]
d_c99_bool_strict.c(518): operand of '++x' must not be bool [335]
d_c99_bool_strict.c(519): operand of '--x' must not be bool [335]
diff -r bdd9cd337356 -r 735617a3507c tests/usr.bin/xlint/lint1/msg_330.c
--- a/tests/usr.bin/xlint/lint1/msg_330.c Sat Jan 16 15:35:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_330.c Sat Jan 16 16:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_330.c,v 1.2 2021/01/16 12:57:37 rillig Exp $ */
+/* $NetBSD: msg_330.c,v 1.3 2021/01/16 16:03:47 rillig Exp $ */
# 3 "msg_330.c"
// Test for message: operand of '%s' must be bool, not '%s' [330]
@@ -17,6 +17,6 @@
example(bool b, char c, int i)
{
called(!b);
- called(!c); /* expect: 330 */
- called(!i); /* expect: 330 */
+ called(!c); /* expect: 330, 334 */
+ called(!i); /* expect: 330, 334 */
}
diff -r bdd9cd337356 -r 735617a3507c tests/usr.bin/xlint/lint1/msg_330.exp
--- a/tests/usr.bin/xlint/lint1/msg_330.exp Sat Jan 16 15:35:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_330.exp Sat Jan 16 16:03:46 2021 +0000
@@ -1,2 +1,4 @@
msg_330.c(20): operand of '!' must be bool, not 'char' [330]
+msg_330.c(20): argument #1 expects '_Bool', gets passed 'int' [334]
msg_330.c(21): operand of '!' must be bool, not 'int' [330]
+msg_330.c(21): argument #1 expects '_Bool', gets passed 'int' [334]
diff -r bdd9cd337356 -r 735617a3507c tests/usr.bin/xlint/lint1/msg_331.c
--- a/tests/usr.bin/xlint/lint1/msg_331.c Sat Jan 16 15:35:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_331.c Sat Jan 16 16:03:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_331.c,v 1.1 2021/01/14 22:18:14 rillig Exp $ */
+/* $NetBSD: msg_331.c,v 1.2 2021/01/16 16:03:47 rillig Exp $ */
# 3 "msg_331.c"
// Test for message: left operand of '%s' must be bool, not '%s' [331]
@@ -16,8 +16,8 @@
example(bool b, char c, int i)
{
test(b && b);
- test(c && b); /* expect: 331 */
- test(i && b); /* expect: 331 */
+ test(c && b); /* expect: 331, 334 */
+ test(i && b); /* expect: 331, 334 */
Home |
Main Index |
Thread Index |
Old Index