public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106842] New: misleading warning : iteration X invokes undefined behavior
@ 2022-09-05 21:43 franckbehaghel_gcc at protonmail dot com
  2022-09-05 22:12 ` [Bug tree-optimization/106842] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: franckbehaghel_gcc at protonmail dot com @ 2022-09-05 21:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106842
           Summary: misleading warning : iteration X invokes undefined
                    behavior
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franckbehaghel_gcc at protonmail dot com
  Target Milestone: ---

Hello,

I get the following misleading warning with gcc 12.2 with -O2/-O3.
11.3 seems fine.

gcc -O2 main.c 
main.c: In function ‘main’:
main.c:16:38: warning: iteration 9 invokes undefined behavior
[-Waggressive-loop-optimizations]
   16 |            for(int64_t k =0; k<i1 ; k++)
      |                                     ~^~
main.c:16:31: note: within this loop
   16 |            for(int64_t k =0; k<i1 ; k++)
      |                              ~^~~

cat main.c
#include "stdio.h"
#include "stdint.h"

int main(int argc, char** argv)
{
   int64_t i1=0;
   int64_t i3=0,i2=0; // warning with this declaration order 
   //int64_t i2=0,i3=0; // but fine (no warning) with this order

   for ( i1 = 0; i1<10 ; i1++)
   {
       for ( ; i2<10 ;i2++ )         
           printf("L2\n");

       for ( ; i3<10 ; i3++ )
           for(int64_t k =0; k<i1 ; k++)
               printf("L3\n");
   }

   printf("i1 %lu i2 %lu i3 %lu\n",i1,i2,i3);  
   return 0;
}


Could someone reproduce ?
The weirdest part of this warning : it depends on the index declaration order.
Even if gcc has a bad(?) way of computing internal range/validity to deduce
such issues, I would expect it in both order.

Regards,

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

end of thread, other threads:[~2024-03-15  0:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 21:43 [Bug c/106842] New: misleading warning : iteration X invokes undefined behavior franckbehaghel_gcc at protonmail dot com
2022-09-05 22:12 ` [Bug tree-optimization/106842] [12 Regression] " pinskia at gcc dot gnu.org
2022-09-05 22:20 ` pinskia at gcc dot gnu.org
2022-09-06  4:51 ` marxin at gcc dot gnu.org
2022-09-06  4:58 ` pinskia at gcc dot gnu.org
2022-09-06  8:35 ` rguenth at gcc dot gnu.org
2022-09-06  8:36 ` [Bug tree-optimization/106842] [12/13 " rguenth at gcc dot gnu.org
2022-12-20 15:23 ` rguenth at gcc dot gnu.org
2023-05-08 12:25 ` [Bug tree-optimization/106842] [12/13/14 " rguenth at gcc dot gnu.org
2024-03-15  0:50 ` [Bug tree-optimization/106842] [12 " law 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).