This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: i386 byteswap.h provoking ``may be undefined'' warnings in gcc3
- To: Paul Haahr <paul at paulhaahr dot com>
- Subject: Re: i386 byteswap.h provoking ``may be undefined'' warnings in gcc3
- From: Andreas Jaeger <aj at suse dot de>
- Date: Thu, 12 Jul 2001 07:09:18 +0200
- Cc: bug-glibc at gnu dot org, gcc-bugs at gcc dot gnu dot org
- References: <8XjdCSp-3@iadd.jivetech.com>
Paul Haahr <paul@paulhaahr.com> writes:
> Gcc 3.0's new ``warning: operation on `p' may be undefined'' is
> (spuriously?) provoked by glibc's <bits/byteswap.h> code for the x86.
>
> Consider the following snippet:
>
> #include <byteswap.h>
>
> unsigned long long f(unsigned long long n)
> {
> unsigned short x = bswap_16(n++);
> unsigned long y = bswap_32(n++);
> unsigned long long z = bswap_64(n++);
> return x + y + z;
> }
>
> The bswap_16 and bswap_32 macros expand into horrible creatures, where a
> reference to n++ appears several times in one expression. This generates
> one warning for the call to bswap_16 and three for the call to bswap_32.
> However, evaluation of the problematic expressions is gated by an
> ``if (__builtin_constant_p(x))'' test which always evaluates to false if
> there are internal side effects, so the ``may be undefined'' path is
> never actually taken.
>
> I can't quite tell if this is a gcc bug or a glibc bug, but I've
> attached a workaround that lives in glibc. It appears to still constant
> fold properly, and generate identical code to the old version, for a few
> small test cases.
But might fail with GCC 3.1 if that one has a more sophisticated
analysis.
> Fixing this in gcc would require not issuing this kind of warning (and
> perhaps others) in code that isn't evaluated due to a __builtin_constant_p
> test.
And that's the way to go.
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj