public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/4751: g++ -O producing incorrect code for ((global1&255)==255 || global2)
@ 2001-10-30 15:46 keenan
  0 siblings, 0 replies; 2+ messages in thread
From: keenan @ 2001-10-30 15:46 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4751
>Category:       optimization
>Synopsis:       g++ -O producing incorrect code for ((global1&255)==255 || global2)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 30 15:46:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     keenan@ghs.com
>Release:        gcc version 3.0.1 (also reproduced on 2.95.2 and 2.95.3)
>Organization:
>Environment:
HP-UX 11.0 (also reproduced on 10.20)
>Description:
An illegal optimization is being performed, such that the attached file produces incorrect output when compiled with -O (or -O1, -O2, -O3). The simple test case breaks down to code that is of the form (where both globals are type int)

if(((global1&255)==global1) || global2)
    exectute_some_statement();

The statement is _always_ executed, even when both expressions are false. If split into two tests:
if(((global1&255)==global1))
    exectute_some_statement();
if(global2)
    exectute_some_statement();

The statment is not executed.

I wasn't able to reproduce this bug on non-HP-UX hosts.
>How-To-Repeat:
g++ -O foo.cc
./a.out
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="foo.cc"
Content-Disposition: inline; filename="foo.cc"

#include <stdio.h>
int global_0 = 0;
int global_neg1 = -1;

int main()
{
    bool test = ((global_neg1&255)==global_neg1);
//    bool test = !(global_neg1&~255);
    if(test || global_0) {
	printf ("Guess again...\n");
    }
    return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: optimization/4751: g++ -O producing incorrect code for ((global1&255)==255 || global2)
@ 2002-04-04  3:14 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-04  3:14 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, keenan, nobody

Synopsis: g++ -O producing incorrect code for ((global1&255)==255 || global2)

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Thu Apr  4 03:14:46 2002
State-Changed-Why:
    Appears to be fixed for gcc 3.1.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4751


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-04 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-30 15:46 optimization/4751: g++ -O producing incorrect code for ((global1&255)==255 || global2) keenan
2002-04-04  3:14 rth

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