optimization/2847: GCC 2.96 with -O2 incorrectly compile if(var==0) break; else printf("test\n"); inside a while
yannick.koehler@colubris.com
yannick.koehler@colubris.com
Wed May 16 13:26:00 GMT 2001
>Number: 2847
>Category: optimization
>Synopsis: GCC 2.96 with -O2 incorrectly compile if(var==0) break; else printf("test\n"); inside a while
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed May 16 13:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Yannick Koehler
>Release: gcc version 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)
>Organization:
>Environment:
Mandrake 7.2 updated to Mandrake 8.0
>Description:
I'm compiling this code with this command:
gcc -O2 ./bug.c
running ./a.out doesn't output the word "Wonderful!" as it should...
CODE:
#include <stdio.h>
int main(int argc, char *argv)
{
int iNbr = 1;
int test = 0;
while(test == 0) {
printf("iNbr = %d\n", iNbr);
if (iNbr == 0)
break;
else {
printf("Wonderful\n");
iNbr--;
}
test = 1;
}
return 0;
}
Instead if display nothing. But if I replace the condition if (iNbr==0) with if (0) things work. Even optimized that code should print Wonderful.
This code works with -O1 -O3 and with 2.95.3
>How-To-Repeat:
take the attachment and compile with 2.96 and option -O2 or -Os
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.c"
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndikKewoJaW50
IGlOYnIgPSAxOwoJaW50IHRlc3QgPSAwOwoJd2hpbGUodGVzdCA9PSAwKSB7CgkJcHJpbnRmKCJp
TmJyID0gJWRcbiIsIGlOYnIpOwoJCWlmIChpTmJyID09IDApCgkJCWJyZWFrOwoJCWVsc2UgewoJ
CQlwcmludGYoIldvbmRlcmZ1bFxuIik7CgkJCWlOYnItLTsKCQl9CQkJCgkJdGVzdCA9IDE7Cgl9
CglyZXR1cm4gMDsKfQo=
More information about the Gcc-bugs
mailing list