public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: yannick.koehler@colubris.com To: gcc-gnats@gcc.gnu.org Subject: optimization/2847: GCC 2.96 with -O2 incorrectly compile if(var==0) break; else printf("test\n"); inside a while Date: Wed, 16 May 2001 13:26:00 -0000 [thread overview] Message-ID: <20010516201759.29516.qmail@sourceware.cygnus.com> (raw) >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=
next reply other threads:[~2001-05-16 13:26 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-05-16 13:26 yannick.koehler [this message] 2001-08-13 16:03 rodrigc
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20010516201759.29516.qmail@sourceware.cygnus.com \ --to=yannick.koehler@colubris.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).