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

Bug#652356: please use argument-safe bswap macros on all architectures



On Fri, Dec 16, 2011 at 03:29:59PM +0000, Thorsten Glaser wrote:
> Source: eglibc
> 
> Hi,
> 
> (from #595496) please make sure that this passes on all
> architectures:
> 
> cat >x.c <<'EOF'
> #include <stddef.h>
> #include <stdint.h>
> #include <byteswap.h>
> 
> uint32_t
> foo(uint32_t *bar, size_t *baz) {
> 	return (bswap_32(bar[(*baz)++]));
> }
> EOF
> gcc -Wall -c x.c
> 
> 
> On amd64 it passes, on m68k it gives:
> 
> x.c: In function ‘foo’:
> x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]
> x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]
> x.c:6:10: warning: operation on ‘*baz’ may be undefined [-Wsequence-point]
> 
> The difference is in /usr/include/$multiarsch/bits/byteswap.h:
> 
> #  define __bswap_32(x) \
>      (__extension__                                                           \
>       ({ register unsigned int __v, __x = (x);                                \
>          if (__builtin_constant_p (__x))                                      \
> […]
> 
> (amd64) vs. (m68k)
> 
> # define __bswap_32(x) \
>   __extension__                                                 \
>   ({ unsigned int __bswap_32_v;                                 \
>      if (__builtin_constant_p (x))                              \
> […]
> 
> That is, the amd64 version evaluates the argument only once.
> 
> Please ensure all flavours of the bswap macros on all architectures
> behave the same; otherwise it’s an introduction to porting issues
> that need not be. Porting is joyful enough already ;-)
> 

The file is different on architectures providing an optimized version of
bswap functions. The m68k optimized version is lagging behind the others 
architectures and as you show, it is therefore broken.

I have dropped it in favor of the default version for the next upload.
This way it will behave like other architectures.

-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net



Reply to: