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: fix wrong warning about uninitiali...



details:   https://anonhg.NetBSD.org/src/rev/f32068a87213
branches:  trunk
changeset: 961087:f32068a87213
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Apr 09 21:42:12 2021 +0000

description:
lint: fix wrong warning about uninitialized _Complex variable

Seen in divxc3.c.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_complex_split.c   |  38 ++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/d_c99_complex_split.exp |   4 +-
 usr.bin/xlint/lint1/tree.c                        |  13 ++++++-
 3 files changed, 46 insertions(+), 9 deletions(-)

diffs (117 lines):

diff -r 71af2176a7c7 -r f32068a87213 tests/usr.bin/xlint/lint1/d_c99_complex_split.c
--- a/tests/usr.bin/xlint/lint1/d_c99_complex_split.c   Fri Apr 09 21:07:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_complex_split.c   Fri Apr 09 21:42:12 2021 +0000
@@ -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 @@
 
 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 */
+}
diff -r 71af2176a7c7 -r f32068a87213 tests/usr.bin/xlint/lint1/d_c99_complex_split.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp Fri Apr 09 21:07:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_complex_split.exp Fri Apr 09 21:42:12 2021 +0000
@@ -1,3 +1,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]
diff -r 71af2176a7c7 -r f32068a87213 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Apr 09 21:07:39 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Apr 09 21:42:12 2021 +0000
@@ -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 @@
 
        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. */



Home | Main Index | Thread Index | Old Index