[prev in list] [next in list] [prev in thread] [next in thread]
List: gcc-bugs
Subject: optimization/4751: g++ -O producing incorrect code for ((global1&255)==255 || global2)
From: keenan () ghs ! com
Date: 2001-10-30 23:36:15
[Download RAW message or body]
> 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;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic