From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22262 invoked by alias); 4 Jan 2015 20:24:38 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22242 invoked by uid 48); 4 Jan 2015 20:24:33 -0000 From: "stuwph at live dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/64491] New: warning: loop exit may only be reached after undefined behavior Date: Sun, 04 Jan 2015 20:24:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: stuwph at live dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-01/txt/msg00178.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64491 Bug ID: 64491 Summary: warning: loop exit may only be reached after undefined behavior Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: stuwph at live dot de gcc -fno-exceptions -Wno-long-long -fno-rtti -ansi -pedantic -DNDEBUG -O3 -DIS_64BIT -DUSE_BSFQ -DUSE_PREFETCH -static -s In function 'void Bitboards::init()': warning: loop exit may only be reached after undefined behavior [-Waggressive-loop-optimizations] for (File f = FILE_A; f <= FILE_H; ++f) ^ note: possible undefined statement is here AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0); ^ /// Bitboards::init() initializes various bitboard tables. It is called at /// startup and relies on global objects to be already zero-initialized. void Bitboards::init() { for (Square s = SQ_A1; s <= SQ_H8; ++s) { SquareBB[s] = 1ULL << s; BSFTable[bsf_index(SquareBB[s])] = s; } for (Bitboard b = 1; b < 256; ++b) MS1BTable[b] = more_than_one(b) ? MS1BTable[b - 1] : lsb(b); for (File f = FILE_A; f <= FILE_H; ++f) FileBB[f] = f > FILE_A ? FileBB[f - 1] << 1 : FileABB; for (Rank r = RANK_1; r <= RANK_8; ++r) RankBB[r] = r > RANK_1 ? RankBB[r - 1] << 8 : Rank1BB; /// warning here: for (File f = FILE_A; f <= FILE_H; ++f) AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f] : 0); for (Rank r = RANK_1; r < RANK_8; ++r) InFrontBB[WHITE][r] = ~(InFrontBB[BLACK][r + 1] = InFrontBB[BLACK][r] | RankBB[r]); ... *** definitely it is a gcc bug, the warning is wrong. My guess is that gcc consider that FileBB[f + 1] could reach out of bound when f == FILE_H, ignoring that out of bound access is guarded by the condition (f < FILE_H) *** solution to let the warning disappear: for (File f = FILE_A; f <= FILE_H; ++f) AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f] : 0);