bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: i386 byteswap.h provoking ``may be undefined'' warnings in gcc3


From: Andreas Jaeger
Subject: Re: i386 byteswap.h provoking ``may be undefined'' warnings in gcc3
Date: Thu, 12 Jul 2001 07:09:18 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Academic Rigor)

Paul Haahr <address@hidden> 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 address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]