Module Name: src Committed By: rillig Date: Sat May 11 15:53:38 UTC 2024
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: msg_162.c t_usage.sh src/usr.bin/xlint/lint1: err.c makeman tree.c Added Files: src/tests/usr.bin/xlint/lint1: msg_379.c Log Message: lint: warn when comparing an integer to a floating point constant To generate a diff of this commit: cvs rdiff -u -r1.1315 -r1.1316 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_162.c cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_379.c cvs rdiff -u -r1.20 -r1.21 src/tests/usr.bin/xlint/lint1/t_usage.sh cvs rdiff -u -r1.242 -r1.243 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/makeman cvs rdiff -u -r1.641 -r1.642 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/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1315 src/distrib/sets/lists/tests/mi:1.1316 --- src/distrib/sets/lists/tests/mi:1.1315 Sun May 5 02:53:01 2024 +++ src/distrib/sets/lists/tests/mi Sat May 11 15:53:38 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1315 2024/05/05 02:53:01 riastradh Exp $ +# $NetBSD: mi,v 1.1316 2024/05/11 15:53:38 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -7509,6 +7509,7 @@ ./usr/tests/usr.bin/xlint/lint1/msg_376.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_377.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_378.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/msg_379.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/op_colon.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/op_colon.exp tests-obsolete obsolete,atf ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/msg_162.c diff -u src/tests/usr.bin/xlint/lint1/msg_162.c:1.8 src/tests/usr.bin/xlint/lint1/msg_162.c:1.9 --- src/tests/usr.bin/xlint/lint1/msg_162.c:1.8 Tue Mar 28 14:44:35 2023 +++ src/tests/usr.bin/xlint/lint1/msg_162.c Sat May 11 15:53:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_162.c,v 1.8 2023/03/28 14:44:35 rillig Exp $ */ +/* $NetBSD: msg_162.c,v 1.9 2024/05/11 15:53:38 rillig Exp $ */ # 3 "msg_162.c" // Test for message: operator '%s' compares '%s' with '%s' [162] @@ -8,6 +8,7 @@ void left_unsigned(unsigned int ui) { + /* expect+1: warning: comparing integer 'unsigned int' to floating point constant -5 [379] */ if (ui < -5.0) { } Index: src/tests/usr.bin/xlint/lint1/t_usage.sh diff -u src/tests/usr.bin/xlint/lint1/t_usage.sh:1.20 src/tests/usr.bin/xlint/lint1/t_usage.sh:1.21 --- src/tests/usr.bin/xlint/lint1/t_usage.sh:1.20 Sat Apr 27 10:08:54 2024 +++ src/tests/usr.bin/xlint/lint1/t_usage.sh Sat May 11 15:53:38 2024 @@ -1,4 +1,4 @@ -# $NetBSD: t_usage.sh,v 1.20 2024/04/27 10:08:54 rillig Exp $ +# $NetBSD: t_usage.sh,v 1.21 2024/05/11 15:53:38 rillig Exp $ # # Copyright (c) 2023 The NetBSD Foundation, Inc. # All rights reserved. @@ -39,13 +39,13 @@ suppress_messages_body() # The largest known message. atf_check \ - "$lint1" -X 378 code.c /dev/null + "$lint1" -X 379 code.c /dev/null # Larger than the largest known message. atf_check \ -s 'exit:1' \ - -e "inline:lint1: invalid message ID '379'\n" \ - "$lint1" -X 379 code.c /dev/null + -e "inline:lint1: invalid message ID '380'\n" \ + "$lint1" -X 380 code.c /dev/null # Whitespace is not allowed before a message ID. atf_check \ Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.242 src/usr.bin/xlint/lint1/err.c:1.243 --- src/usr.bin/xlint/lint1/err.c:1.242 Thu May 9 20:53:13 2024 +++ src/usr.bin/xlint/lint1/err.c Sat May 11 15:53:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $ */ +/* $NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $"); #endif #include <limits.h> @@ -434,6 +434,7 @@ static const char *const msgs[] = { "'%.*s' overlaps earlier '%.*s' on bit %u", // 376 "redundant '\\0' at the end of the format", // 377 "conversion '%.*s' is unreachable by input value", // 378 + "comparing integer '%s' to floating point constant %Lg", // 379 }; static bool is_suppressed[sizeof(msgs) / sizeof(msgs[0])]; Index: src/usr.bin/xlint/lint1/makeman diff -u src/usr.bin/xlint/lint1/makeman:1.9 src/usr.bin/xlint/lint1/makeman:1.10 --- src/usr.bin/xlint/lint1/makeman:1.9 Tue Feb 6 22:47:21 2024 +++ src/usr.bin/xlint/lint1/makeman Sat May 11 15:53:38 2024 @@ -1,5 +1,5 @@ #!/bin/sh -# $NetBSD: makeman,v 1.9 2024/02/06 22:47:21 rillig Exp $ +# $NetBSD: makeman,v 1.10 2024/05/11 15:53:38 rillig Exp $ # # Copyright (c) 2000 The NetBSD Foundation, Inc. # All rights reserved. @@ -38,9 +38,9 @@ list_messages() { -e 's|^'"$tab"'"",.*// '"$2"'[0-9]+$|---'"$tab"'(no longer used)|p' \ "$1" \ | ${SED} -E \ - -e 's,%ld,%d,g' \ - -e 's,%lu,%u,g' \ - -e 's,%llu,%u,g' \ + -e 's,%ld|%jd,%d,g' \ + -e 's,%lu|%llu|%ju,%u,g' \ + -e 's,%Lg,%g,g' \ -e 's|%.\*s|%s|g' \ -e 's|\\"|"|g' \ -e 's|\\\\|\\e|g' \ @@ -49,7 +49,7 @@ list_messages() { } # shellcheck disable=SC2016 -cvsid='$NetBSD: makeman,v 1.9 2024/02/06 22:47:21 rillig Exp $' +cvsid='$NetBSD: makeman,v 1.10 2024/05/11 15:53:38 rillig Exp $' date="$1" year="${date##* }" messages="$(list_messages "$2" "")" Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.641 src/usr.bin/xlint/lint1/tree.c:1.642 --- src/usr.bin/xlint/lint1/tree.c:1.641 Fri May 10 21:43:40 2024 +++ src/usr.bin/xlint/lint1/tree.c Sat May 11 15:53:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.641 2024/05/10 21:43:40 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.641 2024/05/10 21:43:40 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $"); #endif #include <float.h> @@ -758,6 +758,13 @@ balance(op_t op, tnode_t **lnp, tnode_t ? usual_arithmetic_conversion_c90(lt, rt) : usual_arithmetic_conversion_trad(lt, rt); + if (modtab[op].m_comparison + && is_integer(lt) && (*lnp)->tn_op != CON + && is_floating(t) && (*rnp)->tn_op == CON) + /* comparing integer '%s' to floating point constant %Lg */ + warning(379, type_name((*lnp)->tn_type), + (*rnp)->u.value.u.floating); + if (t != lt) *lnp = apply_usual_arithmetic_conversions(op, *lnp, t); if (t != rt) Added files: Index: src/tests/usr.bin/xlint/lint1/msg_379.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_379.c:1.1 --- /dev/null Sat May 11 15:53:39 2024 +++ src/tests/usr.bin/xlint/lint1/msg_379.c Sat May 11 15:53:38 2024 @@ -0,0 +1,31 @@ +/* $NetBSD: msg_379.c,v 1.1 2024/05/11 15:53:38 rillig Exp $ */ +# 3 "msg_379.c" + +// Test for message: comparing integer '%s' to floating point constant %Lg [379] + +/* + * Comparing an integer expression to a floating point constant mixes + * different kinds of types. This mixture is more complicated than necessary, + * thus confusing human readers. + * + * The compilers are fine with this kind of expression: GCC treats the + * constant as an integer even at -O0 while Clang needs at least -O. + */ + +/* lint1-extra-flags: -X 351 */ + +int +comparisons(int x) +{ + if (3 > 123.0) + /* expect+1: warning: statement not reached [193] */ + return 0; + /* expect+1: warning: comparing integer 'int' to floating point constant 123 [379] */ + if (x > 123.0) + return 1; + + // Yoda-style comparisons are unusual enough to not warn about them. + if (123.0 > x) + return 2; + return 3; +}