This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/37569] Loop incorrectly optimized to endless loop with -Os/-O2/-O3



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]