lint: fix wrong warning about uninitialized _Complex variable

Seen in divxc3.c.
This commit is contained in:
rillig 2021-04-09 21:42:12 +00:00
parent 80108d8526
commit c1c59b2873
3 changed files with 46 additions and 9 deletions

View File

@ -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 */
}

View File

@ -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]

View File

@ -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. */