[PATCH, v3] Do not shift by larger than size in hash_bytes.cc

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Sun Sep 19 09:59:00 GMT 2010


The patch below fixes the following build failure on
x86_64-unknown-linux-gnu when --enable-maintainer-mode is used
(which turns on -Werror here):

libtool: compile:  /tmp/build/./gcc/xgcc -shared-libgcc -B/tmp/build/./gcc -nostdinc++ -L/tmp/build/x86_64-unknown-linux-gnu/32/libstdc++-v3/src -L/tmp/build/x86_64-unknown-linux-gnu/32/libstdc++-v3/src/.libs -B/opt/gcc-4.6/x86_64-unknown-linux-gnu/bin/ -B/opt/gcc-4.6/x86_64-unknown-linux-gnu/lib/ -isystem /opt/gcc-4.6/x86_64-unknown-linux-gnu/include -isystem /opt/gcc-4.6/x86_64-unknown-linux-gnu/sys-include -m32 -I/tmp/build/x86_64-unknown-linux-gnu/32/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/tmp/build/x86_64-unknown-linux-gnu/32/libstdc++-v3/include -I/tmp/gcc/libstdc++-v3/libsupc++ -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Werror -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -g -O2 -D_GNU_SOURCE -m32 -std=gnu++0x -c ../../../../../gcc/libstdc++-v3/src/hash_bytes.cc  -fPIC -DPIC -o .libs/hash_bytes.o
../../../../../gcc/libstdc++-v3/src/hash_bytes.cc: In function ‘std::size_t {anonymous}::shift_mix(std::size_t)’:
../../../../../gcc/libstdc++-v3/src/hash_bytes.cc:62:22: error: right shift count >= width of type [-Werror]
cc1plus: all warnings being treated as errors
make[8]: *** [hash_bytes.lo] Error 1
make[8]: Leaving directory `/tmp/build/x86_64-unknown-linux-gnu/32/libstdc++-v3/src'

Regtested, no regressions.  It seems to me however that the warning
hints that the code needs more adjustments for 32 bit size_t, or that
load_bytes and shift_mix can be enclosed in '#if __SIZEOF_SIZE_T__ == 8'
because they seem unused in the 32 bit case.

If not, OK for trunk?

Thanks,
Ralf

Do not shift by larger than size.

libstdc++-v3/ChangeLog:
2010-09-19  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	* src/hash_bytes.cc (shift_mix): Do not shift by larger than size.

diff --git a/libstdc++-v3/src/hash_bytes.cc b/libstdc++-v3/src/hash_bytes.cc
index 5dfa1ee..9db25a2 100644
--- a/libstdc++-v3/src/hash_bytes.cc
+++ b/libstdc++-v3/src/hash_bytes.cc
@@ -59,7 +59,7 @@ namespace
 
   inline std::size_t
   shift_mix(std::size_t v)
-  { return v ^ (v >> 47);}
+  { return v ^ ((v >> 31) >> 16);}
 }
 
 namespace std



More information about the Gcc-patches mailing list