public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112767] New: [14 regression] spurious -Waggressive-loop-optimizations
@ 2023-11-29 18:24 sss@li-snyder.org
  2023-11-29 18:34 ` [Bug tree-optimization/112767] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sss@li-snyder.org @ 2023-11-29 18:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112767

            Bug ID: 112767
           Summary: [14 regression] spurious
                    -Waggressive-loop-optimizations
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sss@li-snyder.org
  Target Milestone: ---

With a recent checkout of gcc14 (20231129), on a x86_64-pc-linux-gnu host,
the following source gives a seemingly bogus -Waggressive-loop-optimizations
warning with -O3:

--------------------------------------------------------------
double reg_dict[32];

void foo(int);

void initialize()
{
  int i=8;
  for (int phi=0; phi<8; ++phi) {
    reg_dict[i]=0;
    int sn = 0;
    if (i < 16) sn = 20;
    foo(sn);
    ++i;
  }
}
--------------------------------------------------------------

$ g++ -c -O3 x.cc
x.cc: In function ‘void initialize()’:
x.cc:9:16: warning: iteration 16 invokes undefined behavior
[-Waggressive-loop-optimizations]
    9 |     reg_dict[i]=0;
      |     ~~~~~~~~~~~^~
x.cc:8:22: note: within this loop
    8 |   for (int phi=0; phi<8; ++phi) {
      |                   ~~~^~


This is a confusing warning, as the containing loop is executed only 8 times.
Exactly which undefined behavior is meant is also not spelled out.
From the context, i'd guess it to be an out-of-bounds array write,
but that's a false positive.

The warning happens with -O3 but not with lower optimization levels.
It also does not occur with gcc 13.2.1 20230728.

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

end of thread, other threads:[~2023-11-30 12:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 18:24 [Bug c++/112767] New: [14 regression] spurious -Waggressive-loop-optimizations sss@li-snyder.org
2023-11-29 18:34 ` [Bug tree-optimization/112767] " pinskia at gcc dot gnu.org
2023-11-29 22:08 ` ppalka at gcc dot gnu.org
2023-11-30 11:42 ` [Bug tree-optimization/112767] [14 regression] spurious -Waggressive-loop-optimizations since r14-2944-g3d48c11ad082de rguenth at gcc dot gnu.org
2023-11-30 12:35 ` cvs-commit at gcc dot gnu.org
2023-11-30 12:36 ` rguenth 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).