Module Name: src
Committed By: rillig
Date: Fri Apr 9 21:42:12 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_complex_split.c
d_c99_complex_split.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: fix wrong warning about uninitialized _Complex variable
Seen in divxc3.c.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_complex_split.c
cvs rdiff -u -r1.1 -r1.2 \
src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp
cvs rdiff -u -r1.274 -r1.275 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/d_c99_complex_split.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_complex_split.c:1.6 src/tests/usr.bin/xlint/lint1/d_c99_complex_split.c:1.7
--- src/tests/usr.bin/xlint/lint1/d_c99_complex_split.c:1.6 Fri Apr 9 21:07:39 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_complex_split.c Fri Apr 9 21:42:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_complex_split.c,v 1.6 2021/04/09 21:07:39 rillig Exp $ */
+/* $NetBSD: d_c99_complex_split.c,v 1.7 2021/04/09 21:42:12 rillig Exp $ */
# 3 "d_c99_complex_split.c"
/*
@@ -22,32 +22,62 @@ a(void)
void sink(double _Complex);
+/*
+ * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
+ * '__real__ c' was assigned, 'c may be used before set'.
+ *
+ * As of 2021-04-09, support for _Complex is still very incomplete, see
+ * build_real_imag for details. For example, lint does not know that after
+ * the assignment to '__real__ c', the variable is partially initialized.
+ */
void
set_complex_complete(double re, double im)
{
double _Complex c;
- __real__ c = re; /* FIXME *//* expect: may be used before set */
+ __real__ c = re;
__imag__ c = im;
sink(c);
}
+/*
+ * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
+ * '__real__ c' was assigned, 'c may be used before set'.
+ *
+ * As of 2021-04-09, support for _Complex is still very incomplete, see
+ * build_real_imag for details.
+ */
void
set_complex_only_real(double re)
{
double _Complex c;
- __real__ c = re; /* FIXME *//* expect: may be used before set */
+ __real__ c = re;
/* __imag__ c is left uninitialized */
sink(c); /* XXX: may be used before set */
}
+/*
+ * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
+ * '__imag__ c' was assigned, 'c may be used before set'.
+ *
+ * As of 2021-04-09, support for _Complex is still very incomplete, see
+ * build_real_imag for details.
+ */
void
set_complex_only_imag(double im)
{
double _Complex c;
/* __real__ c is left uninitialized */
- __imag__ c = im; /* FIXME *//* expect: may be used before set */
+ __imag__ c = im;
sink(c); /* XXX: may be used before set */
}
+
+/* Just to keep the .exp file alive. */
+void
+trigger_warning(double _Complex c)
+{
+ c += 1.0;
+ return c | c; /* expect: incompatible types */
+}
Index: src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp:1.1 src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp:1.2
--- src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp:1.1 Fri Apr 9 21:07:39 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp Fri Apr 9 21:42:12 2021
@@ -1,3 +1 @@
-d_c99_complex_split.c(30): warning: c may be used before set [158]
-d_c99_complex_split.c(40): warning: c may be used before set [158]
-d_c99_complex_split.c(51): warning: c may be used before set [158]
+d_c99_complex_split.c(82): error: operands of '|' have incompatible types (double _Complex != double _Complex) [107]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.274 src/usr.bin/xlint/lint1/tree.c:1.275
--- src/usr.bin/xlint/lint1/tree.c:1.274 Fri Apr 9 20:00:06 2021
+++ src/usr.bin/xlint/lint1/tree.c Fri Apr 9 21:42:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.274 2021/04/09 20:00:06 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.275 2021/04/09 21:42:12 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.274 2021/04/09 20:00:06 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.275 2021/04/09 21:42:12 rillig Exp $");
#endif
#include <float.h>
@@ -2543,6 +2543,15 @@ build_real_imag(op_t op, tnode_t *ln)
lint_assert(ln != NULL);
+ if (ln->tn_op == NAME) {
+ /*
+ * This may be too much, but it avoids wrong warnings.
+ * See d_c99_complex_split.c.
+ */
+ mark_as_used(ln->tn_sym, false, false);
+ mark_as_set(ln->tn_sym);
+ }
+
switch (ln->tn_type->t_tspec) {
case LCOMPLEX:
/* XXX: integer and LDOUBLE don't match. */