This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[M68K] avoid compiler warnings from bswap_32 (*p++) usage


Calling bswap_32 on m68k (classic, not ColdFire) with a parameter
expression that contains a side-effect (like *p++) makes gcc emit
"operation on <var> may be undefined" warnings.  In my case it broke
the build of elfutils.

The warnings don't occur on other archs because all other bswap_32
macros in glibc bind the parameter expression to a local variable,
which ensures that it is evaluated exactly once.

Fix below.  Ok for trunk?

2011-03-06  Mikael Pettersson  <mikpe@it.uu.se>

	* sysdeps/m68k/bits/byteswap.h (__bswap_32): Evaluate
	parameter exactly once.  Remove redundant cast.

--- ports/sysdeps/m68k/bits/byteswap.h.~1~	2010-06-05 00:41:32.000000000 +0200
+++ ports/sysdeps/m68k/bits/byteswap.h	2011-03-06 17:07:14.000000000 +0100
@@ -50,15 +50,15 @@ __bswap_16 (unsigned short int __bsx)
 #if defined __GNUC__ && __GNUC__ >= 2 && !defined(__mcoldfire__)
 # define __bswap_32(x) \
   __extension__							\
-  ({ unsigned int __bswap_32_v;					\
-     if (__builtin_constant_p (x))				\
-       __bswap_32_v = __bswap_constant_32 (x);			\
+  ({ unsigned int __bswap_32_v, __bswap_32_x = (x);		\
+     if (__builtin_constant_p (__bswap_32_x))			\
+       __bswap_32_v = __bswap_constant_32 (__bswap_32_x);	\
      else							\
        __asm__ __volatile__ ("ror%.w %#8, %0;"			\
 			     "swap %0;"				\
 			     "ror%.w %#8, %0"			\
 			     : "=d" (__bswap_32_v)		\
-			     : "0" ((unsigned int) (x)));	\
+			     : "0" (__bswap_32_x));		\
      __bswap_32_v; })
 #else
 static __inline unsigned int


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]