[Bug regression/56844] Loop condition wrongly optimized from < to !=

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 4 16:38:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56844

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-04-04 16:38:41 UTC ---
>( str[i] != '\0' ) && ( i < 16 )

You access str[16] which is undefined behavior.  Switch around the check for i
and str[i] will work correctly.

That is:
  for( i = 0;  ( i < 16 ) && ( str[i] != '\0' ); i++ );



More information about the Gcc-bugs mailing list