public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "franckbehaghel_gcc at protonmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106842] New: misleading warning : iteration X invokes undefined behavior Date: Mon, 05 Sep 2022 21:43:22 +0000 [thread overview] Message-ID: <bug-106842-4@http.gcc.gnu.org/bugzilla/> (raw) 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,
next reply other threads:[~2022-09-05 21:43 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-05 21:43 franckbehaghel_gcc at protonmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-106842-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).