[Bug regression/56844] New: Loop condition wrongly optimized from < to !=
holger.hopp at sap dot com
gcc-bugzilla@gcc.gnu.org
Thu Apr 4 16:23:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56844
Bug #: 56844
Summary: Loop condition wrongly optimized from < to !=
Classification: Unclassified
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: regression
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: holger.hopp@sap.com
Following code is optimized wrong with gcc-4.8 -O2.
It works correct with gcc-4.8 -O1 and gcc-4.7 -O2.
Somehow the 'i < 16' condition of the second loop is optimized to 'i != 16'
(runs second loop until segfault / stack overflow).
[gcc-4_8-branch revision 197479, x86_64]
int printf (const char *format, ...);
char* strncpy (char * dest, const char * src, unsigned long n);
int main()
{
int i;
char str[16];
strncpy( str, "abcdefghijklmnop", 16 );
for( i = 0; ( str[i] != '\0' ) && ( i < 16 ); i++ );
for( ; i < 16; i++ ) str[i] = ' ';
printf ("str = \"%s\"\n", str);
return 0;
}
More information about the Gcc-bugs
mailing list