This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Revised patch for compare1.c test failures
- To: gcc-patches at gcc dot gnu dot org, zack at rabi dot columbia dot edu
- Subject: Re: Revised patch for compare1.c test failures
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Mon, 20 Dec 1999 10:56:07 -0500 (EST)
> From: Zack Weinberg <zack@rabi.columbia.edu>
>
> Here is a revised and somewhat less invasive patch which corrects the
> compare1.c test failures and some (not all) of the warnings in the
> compiler itself. Unfortunately, it creates a pile of new warnings
> too, 37 total, almost all spurious. It objects to code of the form
>
> expr ? (a = b) : (c = d);
>
> where a is unsigned and c is signed. In this context, the ? :
> expression is being evaluated exclusively for its side effects and we
> don't care that the signednesses don't match. The warning is being
> emitted from build_conditional_expr, where we don't know what the
> context is. It can be silenced by putting (void) on both branches,
> but that is not K+R compatile...
>
> Suggestions would be appreciated.
>
> zw
>
> * c-decl.c (finish_enum): Give the DECL_INITIAL of each enumerator
> the type of the enumeration.
> * c-typeck.c (build_conditional_expr): Warn for expr ? a : b where a
> is signed and b is unsigned, or vice versa, if -Wsign-compare.
> * testsuite/gcc.dg/compare1.c: Deobfuscate. Test both
> expr ? DImode : SImode and expr ? DImode : -1.
So I tried it out and it does indeed remove the original spurious
warnings and add the 37 new ones when you have mixed signed/unsigned
in ?: branches.
One question I have, should enums be treated as signed or unsigned?
(I thought they were int by default, by then I'm no expert.)
Even if enums are really unsigned, isn't it possible to avoid warnings
for something like this:
expr ? 1U : -1
because both 1U and -1 fit into an int?
The enums would be a similar case if the max value of the enum was
less than the max value of the other branch's type. Maybe that's
a way to elide the warning.
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions