This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37569] Loop incorrectly optimized to endless loop with -Os/-O2/-O3
- From: "brian at dessent dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Sep 2008 10:45:37 -0000
- Subject: [Bug c/37569] Loop incorrectly optimized to endless loop with -Os/-O2/-O3
- References: <bug-37569-16736@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #10 from brian at dessent dot net 2008-09-18 10:45 -------
Subject: Re: Loop incorrectly optimized to endless loop with
-Os/-O2/-O3
That fact that the hardware allows it doesn't change the fact that it's
still invalid in ISO C, and that is the spec that gcc follows.
Seems to me you can avoid invoking undefined behavior by:
uint16 i = 0x0FFE, sum = 0;
do {
i -= sizeof (uint16);
sum += *((uint16 *)i);
} while (i);
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37569