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: don't wrongly warn about overflow ...



details:   https://anonhg.NetBSD.org/src/rev/ae7bbbdfa30b
branches:  trunk
changeset: 374206:ae7bbbdfa30b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Apr 11 00:03:42 2023 +0000

description:
lint: don't wrongly warn about overflow in complex constants

Seen in lib/libm.

diffstat:

 tests/usr.bin/xlint/lint1/msg_142.c |   7 +++++--
 usr.bin/xlint/lint1/lex.c           |  15 ++++++++-------
 usr.bin/xlint/lint1/tree.c          |  12 +++++++++---
 3 files changed, 22 insertions(+), 12 deletions(-)

diffs (96 lines):

diff -r c6ad5b07c319 -r ae7bbbdfa30b tests/usr.bin/xlint/lint1/msg_142.c
--- a/tests/usr.bin/xlint/lint1/msg_142.c       Mon Apr 10 23:56:30 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_142.c       Tue Apr 11 00:03:42 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_142.c,v 1.9 2023/04/10 23:52:49 rillig Exp $       */
+/*     $NetBSD: msg_142.c,v 1.10 2023/04/11 00:03:42 rillig Exp $      */
 # 3 "msg_142.c"
 
 // Test for message: floating point overflow on operator '%s' [142]
@@ -20,5 +20,8 @@
 /* expect+1: warning: floating point overflow on operator '*' [142] */
 double dbl = 1e100 * 1e100 * 1e100 * 1e100 * 1e100;
 
-/* expect+1: warning: floating point overflow on operator '+' [142] */
+/*
+ * Ensure that an addition in the complex number space doesn't generate
+ * wrong warnings. Lint doesn't model complex constants accurately.
+ */
 double _Complex complex_sum = 1e308 + 1e308i;
diff -r c6ad5b07c319 -r ae7bbbdfa30b usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Mon Apr 10 23:56:30 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Tue Apr 11 00:03:42 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.157 2023/04/07 11:08:31 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.158 2023/04/11 00:03:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.157 2023/04/07 11:08:31 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.158 2023/04/11 00:03:42 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -626,19 +626,20 @@ lex_floating_constant(const char *yytext
        const char *cp = yytext;
        size_t len = yyleng;
 
-       if (cp[len - 1] == 'i')
-               len--;          /* imaginary, do nothing for now */
+       bool imaginary = cp[len - 1] == 'i';
+       if (imaginary)
+               len--;
 
        char c = cp[len - 1];
        tspec_t typ;
        if (c == 'f' || c == 'F') {
-               typ = FLOAT;
+               typ = imaginary ? FCOMPLEX : FLOAT;
                len--;
        } else if (c == 'l' || c == 'L') {
-               typ = LDOUBLE;
+               typ = imaginary ? LCOMPLEX : LDOUBLE;
                len--;
        } else
-               typ = DOUBLE;
+               typ = imaginary ? DCOMPLEX : DOUBLE;
 
        if (!allow_c90 && typ != DOUBLE) {
                /* suffixes F and L are illegal in traditional C */
diff -r c6ad5b07c319 -r ae7bbbdfa30b usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Apr 10 23:56:30 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Apr 11 00:03:42 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.507 2023/03/28 14:44:35 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.508 2023/04/11 00:03:42 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.507 2023/03/28 14:44:35 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.508 2023/04/11 00:03:42 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1584,7 +1584,13 @@ fold_float(tnode_t *tn)
        }
 
        lint_assert(fpe != 0 || isnan((double)v->v_ldbl) == 0);
-       if (fpe != 0 || isfinite((double)v->v_ldbl) == 0 ||
+       if (is_complex(v->v_tspec)) {
+               /*
+                * Don't warn, as lint doesn't model the imaginary part of
+                * complex numbers.
+                */
+               fpe = 0;
+       } else if (fpe != 0 || isfinite((double)v->v_ldbl) == 0 ||
            (t == FLOAT &&
             (v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) ||
            (t == DOUBLE &&



Home | Main Index | Thread Index | Old Index