Module Name: src
Committed By: rillig
Date: Tue Apr 11 00:03:42 UTC 2023
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_142.c
src/usr.bin/xlint/lint1: lex.c tree.c
Log Message:
lint: don't wrongly warn about overflow in complex constants
Seen in lib/libm.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_142.c
cvs rdiff -u -r1.157 -r1.158 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.507 -r1.508 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/msg_142.c
diff -u src/tests/usr.bin/xlint/lint1/msg_142.c:1.9 src/tests/usr.bin/xlint/lint1/msg_142.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_142.c:1.9 Mon Apr 10 23:52:49 2023
+++ src/tests/usr.bin/xlint/lint1/msg_142.c Tue Apr 11 00:03:42 2023
@@ -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;
Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.157 src/usr.bin/xlint/lint1/lex.c:1.158
--- src/usr.bin/xlint/lint1/lex.c:1.157 Fri Apr 7 11:08:31 2023
+++ src/usr.bin/xlint/lint1/lex.c Tue Apr 11 00:03:42 2023
@@ -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 */
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.507 src/usr.bin/xlint/lint1/tree.c:1.508
--- src/usr.bin/xlint/lint1/tree.c:1.507 Tue Mar 28 14:44:35 2023
+++ src/usr.bin/xlint/lint1/tree.c Tue Apr 11 00:03:42 2023
@@ -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 &&