public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64491] New: warning: loop exit may only be reached after undefined behavior
@ 2015-01-04 20:24 stuwph at live dot de
  2015-01-04 20:46 ` [Bug c++/64491] " redi at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: stuwph at live dot de @ 2015-01-04 20:24 UTC (permalink / raw)
  To: gcc-bugs

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);


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-03-18 14:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-04 20:24 [Bug c++/64491] New: warning: loop exit may only be reached after undefined behavior stuwph at live dot de
2015-01-04 20:46 ` [Bug c++/64491] " redi at gcc dot gnu.org
2015-01-10 15:58 ` joona.kiiski at iki dot fi
2015-01-10 16:04 ` joona.kiiski at iki dot fi
2015-01-10 16:49 ` [Bug c++/64491] [5 Regression] incorrect " Joost.VandeVondele at mat dot ethz.ch
2015-01-11 22:10 ` [Bug middle-end/64491] " joona.kiiski at gmail dot com
2015-01-12  7:18 ` Joost.VandeVondele at mat dot ethz.ch
2015-02-09  0:06 ` pinskia at gcc dot gnu.org
2015-02-18 13:57 ` jakub at gcc dot gnu.org
2015-02-18 16:25 ` ams at gcc dot gnu.org
2015-02-18 16:28 ` jakub at gcc dot gnu.org
2015-02-20 11:28 ` ams at gcc dot gnu.org
2015-02-24 17:01 ` ams at gcc dot gnu.org
2015-02-24 19:18 ` jakub at gcc dot gnu.org
2015-03-18 12:50 ` rguenth at gcc dot gnu.org
2015-03-18 12:53 ` jakub at gcc dot gnu.org
2015-03-18 14:27 ` ams at gcc dot gnu.org
2015-03-18 14:29 ` ams at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).