Module Name: src Committed By: rillig Date: Sun Aug 22 21:17:04 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: expr_fold.c expr_fold.exp expr_fold_strict_bool.c expr_fold_strict_bool.exp src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix folding of comparisons in constant expressions To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/expr_fold.c \ src/tests/usr.bin/xlint/lint1/expr_fold.exp cvs rdiff -u -r1.1 -r1.2 \ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c \ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp cvs rdiff -u -r1.344 -r1.345 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/expr_fold.c diff -u src/tests/usr.bin/xlint/lint1/expr_fold.c:1.3 src/tests/usr.bin/xlint/lint1/expr_fold.c:1.4 --- src/tests/usr.bin/xlint/lint1/expr_fold.c:1.3 Sun Aug 22 20:14:24 2021 +++ src/tests/usr.bin/xlint/lint1/expr_fold.c Sun Aug 22 21:17:04 2021 @@ -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 @@ fold_bitor(void) * 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 @@ struct ctassert5_struct { <= ((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; }; Index: src/tests/usr.bin/xlint/lint1/expr_fold.exp diff -u src/tests/usr.bin/xlint/lint1/expr_fold.exp:1.3 src/tests/usr.bin/xlint/lint1/expr_fold.exp:1.4 --- src/tests/usr.bin/xlint/lint1/expr_fold.exp:1.3 Sun Aug 22 20:14:24 2021 +++ src/tests/usr.bin/xlint/lint1/expr_fold.exp Sun Aug 22 21:17:04 2021 @@ -51,4 +51,3 @@ expr_fold.c(204): warning: integer overf 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] Index: src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c diff -u src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c:1.1 src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c:1.2 --- src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c:1.1 Sun Aug 22 20:56:51 2021 +++ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c Sun Aug 22 21:17:04 2021 @@ -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 @@ struct fold_64_bit { /* 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. */ - /* expect+1: error: illegal bit-field size: 255 [36] */ + /* + * 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_bad: 1ULL << 63 < 1ULL ? 1 : -1; }; Index: src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp diff -u src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp:1.1 src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp:1.2 --- src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp:1.1 Sun Aug 22 20:56:51 2021 +++ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp Sun Aug 22 21:17:04 2021 @@ -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] Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.344 src/usr.bin/xlint/lint1/tree.c:1.345 --- src/usr.bin/xlint/lint1/tree.c:1.344 Sat Aug 21 11:27:26 2021 +++ src/usr.bin/xlint/lint1/tree.c Sun Aug 22 21:17:04 2021 @@ -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 @@ fold(tnode_t *tn) tnode_t *cn; v = xcalloc(1, sizeof(*v)); - v->v_tspec = t = tn->tn_type->t_tspec; + v->v_tspec = tn->tn_type->t_tspec; - utyp = t == PTR || is_uinteger(t); + 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;