--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: g++-4.9: false-positive -Warray-bounds apprently due to wrong integer-range inference
- From: Yann Dirson <ydirson@free.fr>
- Date: Sat, 11 Apr 2015 15:20:00 +0200
- Message-id: <20150411132000.GA12539@home.lan>
Package: g++-4.9
Version: 4.9.2-10
Severity: normal
This warning can be seen while compiling skaakii-1.0.0 on several
architectures (looks like it includes some 64bit archs, plus sparc).
It does not appear with g++-4.8.
https://qa.debian.org/bls/packages/s/sjaakii.html
http://buildd.debian.org/status/fetch.php?pkg=sjaakii&arch=arm64&ver=1.0.0-1&stamp=1427152943
| SjaakII-1.0.0$ g++-4.8 -g -O2 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -O3 -finline -Wall -Wextra -Wno-unused -DSJAAKIIVERSION=\""1.0.0"\" -DDATADIR=\"/usr/share/games/sjaakii/\" -DHAVE_READLINE -I/work/yann/deb/sjaak/SjaakII-1.0.0/include -I/work/yann/deb/sjaak/SjaakII-1.0.0/obj-x86_64-linux-gnu/include -o obj-x86_64-linux-gnu/CMakeFiles/sjaakii.dir/src/xboard.o -c /work/yann/deb/sjaak/SjaakII-1.0.0/src/xboard.cc
|
| SjaakII-1.0.0$ g++-4.9 -g -O2 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -O3 -finline -Wall -Wextra -Wno-unused -DSJAAKIIVERSION=\""1.0.0"\" -DDATADIR=\"/usr/share/games/sjaakii/\" -DHAVE_READLINE -I/work/yann/deb/sjaak/SjaakII-1.0.0/include -I/work/yann/deb/sjaak/SjaakII-1.0.0/obj-x86_64-linux-gnu/include -o obj-x86_64-linux-gnu/CMakeFiles/sjaakii.dir/src/xboard.o -c /work/yann/deb/sjaak/SjaakII-1.0.0/src/xboard.cc
| In file included from /work/yann/deb/sjaak/SjaakII-1.0.0/include/sjaak.h:4:0,
| from /work/yann/deb/sjaak/SjaakII-1.0.0/src/xboard.cc:27:
| /work/yann/deb/sjaak/SjaakII-1.0.0/include/bitboard.h: In function ‘game_t* create_capablanca_game(const char*)’:
| /work/yann/deb/sjaak/SjaakII-1.0.0/include/bitboard.h:478:65: warning: array subscript is above array bounds [-Warray-bounds]
| board_between[square][attack] |= square_bitboards[pack_rank_file(n, file)];
| ^
| /work/yann/deb/sjaak/SjaakII-1.0.0/include/bitboard.h:478:65: warning: array subscript is above array bounds [-Warray-bounds]
| /work/yann/deb/sjaak/SjaakII-1.0.0/include/bitboard.h:478:65: warning: array subscript is above array bounds [-Warray-bounds]
|
| SjaakII-1.0.0$
Sorry for the lack of a minimal testcase. What I've been able to
gather till now, is that we have 2 similar cases, with only one
triggering the warning:
473: for (int n=file;n<=unpack_file(attack);n++)
474: board_between[square][attack] |= square_bitboards[pack_rank_file(rank, n)];
477: for (int n=rank;n<=unpack_rank(attack);n++)
478: board_between[square][attack] |= square_bitboards[pack_rank_file(n, file)];
... and that the above-bound alert is linked to the infered values for
the loop range. Whereas this ensures there is no warning:
| static inline int unpack_file(int packed)
| {
| return packed_file_rank[packed] & 0xf;
| }
... this does not:
| static inline int unpack_rank(int packed)
| {
| return packed_file_rank[packed] >> 4;
| }
Changing the latter to "return (packed_file_rank[packed] >> 4) &
0xf;", which should show no difference because packed_file_rank is an
uint8_t[], does indeed silence the warning, which seems to show that
the range of that return value was wrongly infered.
-- System Information:
Debian Release: 8.0
APT prefers testing
APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (101, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)
Versions of packages g++-4.9 depends on:
ii gcc-4.9 4.9.2-10
ii gcc-4.9-base 4.9.2-10
ii libc6 2.19-17
ii libcloog-isl4 0.18.2-1+b2
ii libgmp10 2:6.0.0+dfsg-6
ii libisl10 0.12.2-2
ii libmpc3 1.0.2-1
ii libmpfr4 3.1.2-2
ii libstdc++-4.9-dev 4.9.2-10
ii zlib1g 1:1.2.8.dfsg-2+b1
g++-4.9 recommends no packages.
Versions of packages g++-4.9 suggests:
ii g++-4.9-multilib 4.9.2-10
ii gcc-4.9-doc 4.9.1-3
pn libstdc++6-4.9-dbg <none>
-- no debconf information
--- End Message ---