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: fix folding of comparisons in cons...
details: https://anonhg.NetBSD.org/src/rev/53dbbcb95a22
branches: trunk
changeset: 1023081:53dbbcb95a22
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Aug 22 21:17:04 2021 +0000
description:
lint: fix folding of comparisons in constant expressions
diffstat:
tests/usr.bin/xlint/lint1/expr_fold.c | 10 +++++++---
tests/usr.bin/xlint/lint1/expr_fold.exp | 1 -
tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c | 12 +++++++++---
tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp | 2 +-
usr.bin/xlint/lint1/tree.c | 11 ++++++-----
5 files changed, 23 insertions(+), 13 deletions(-)
diffs (105 lines):
diff -r 7a3ca413748e -r 53dbbcb95a22 tests/usr.bin/xlint/lint1/expr_fold.c
--- a/tests/usr.bin/xlint/lint1/expr_fold.c Sun Aug 22 20:56:51 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold.c Sun Aug 22 21:17:04 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_fold.c,v 1.3 2021/08/22 20:14:24 rillig Exp $ */
+/* $NetBSD: expr_fold.c,v 1.4 2021/08/22 21:17:04 rillig Exp $ */
# 3 "expr_fold.c"
/*
@@ -292,6 +292,12 @@
* expanded to a real monster expression.
*
* __CTASSERT(MUL_OK(uint64_t, MAX_N_BLOCKS, MAX_BLOCKSIZE));
+ *
+ * Before tree.c 1.345 from 2021-08-22, lint wrongly assumed that the result
+ * of all binary operators were the common arithmetic type, but that was
+ * wrong for the comparison operators. The expression '1ULL < 2ULL' does not
+ * have type 'unsigned long long' but 'int' in default mode, or '_Bool' in
+ * strict bool mode.
*/
struct ctassert5_struct {
unsigned int member:
@@ -300,7 +306,5 @@
<=
((1ULL << 63) + 1 < 1 ? ~(1ULL << 63) : ~0ULL) / 0xfffffe00U
? 1
- /* FIXME: the above '(1ULL << 63) + 1' is wrong */
- /* expect+1: error: illegal bit-field size: 255 [36] */
: -1;
};
diff -r 7a3ca413748e -r 53dbbcb95a22 tests/usr.bin/xlint/lint1/expr_fold.exp
--- a/tests/usr.bin/xlint/lint1/expr_fold.exp Sun Aug 22 20:56:51 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold.exp Sun Aug 22 21:17:04 2021 +0000
@@ -51,4 +51,3 @@
expr_fold.c(207): warning: integer overflow detected, op << [141]
expr_fold.c(211): warning: shift amount 104 is greater than bit-size 32 of 'unsigned int' [122]
expr_fold.c(223): warning: shift amount 104 is greater than bit-size 32 of 'int' [122]
-expr_fold.c(305): error: illegal bit-field size: 255 [36]
diff -r 7a3ca413748e -r 53dbbcb95a22 tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c
--- a/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c Sun Aug 22 20:56:51 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c Sun Aug 22 21:17:04 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_fold_strict_bool.c,v 1.1 2021/08/22 20:56:51 rillig Exp $ */
+/* $NetBSD: expr_fold_strict_bool.c,v 1.2 2021/08/22 21:17:04 rillig Exp $ */
# 3 "expr_fold_strict_bool.c"
/*
@@ -28,8 +28,14 @@
/* expect+1: error: illegal bit-field size: 255 [36] */
_Bool lt_unsigned_small_bad: 3ULL < 1ULL ? 1 : -1;
- /* FIXME: 1 is much smaller than 1ULL << 63. */
+ /*
+ * Before tree.c 1.345 from 2021-08-22, lint wrongly assumed that the
+ * result of all binary operators were the common arithmetic type,
+ * but that was wrong for the comparison operators. The expression
+ * '1ULL < 2ULL' does not have type 'unsigned long long' but 'int' in
+ * default mode, or '_Bool' in strict bool mode.
+ */
+ _Bool lt_unsigned_big_ok: 1ULL < 1ULL << 63 ? 1 : -1;
/* expect+1: error: illegal bit-field size: 255 [36] */
- _Bool lt_unsigned_big_ok: 1ULL < 1ULL << 63 ? 1 : -1;
_Bool lt_unsigned_big_bad: 1ULL << 63 < 1ULL ? 1 : -1;
};
diff -r 7a3ca413748e -r 53dbbcb95a22 tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp
--- a/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp Sun Aug 22 20:56:51 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp Sun Aug 22 21:17:04 2021 +0000
@@ -1,4 +1,4 @@
expr_fold_strict_bool.c(21): error: illegal bit-field size: 255 [36]
expr_fold_strict_bool.c(25): error: illegal bit-field size: 255 [36]
expr_fold_strict_bool.c(29): error: illegal bit-field size: 255 [36]
-expr_fold_strict_bool.c(33): error: illegal bit-field size: 255 [36]
+expr_fold_strict_bool.c(40): error: illegal bit-field size: 255 [36]
diff -r 7a3ca413748e -r 53dbbcb95a22 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Aug 22 20:56:51 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Aug 22 21:17:04 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.344 2021/08/21 11:27:26 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.345 2021/08/22 21:17:04 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.344 2021/08/21 11:27:26 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.345 2021/08/22 21:17:04 rillig Exp $");
#endif
#include <float.h>
@@ -3028,9 +3028,10 @@
tnode_t *cn;
v = xcalloc(1, sizeof(*v));
- v->v_tspec = t = tn->tn_type->t_tspec;
-
- utyp = t == PTR || is_uinteger(t);
+ v->v_tspec = tn->tn_type->t_tspec;
+
+ t = tn->tn_left->tn_type->t_tspec;
+ utyp = !is_integer(t) || is_uinteger(t);
ul = sl = tn->tn_left->tn_val->v_quad;
if (modtab[tn->tn_op].m_binary)
ur = sr = tn->tn_right->tn_val->v_quad;
Home |
Main Index |
Thread Index |
Old Index