This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/9041: gcc 3.2.1: inconsistent behaviour with/without -O2
- From: mia at de dot uu dot net
- To: gcc-gnats at gcc dot gnu dot org
- Date: 23 Dec 2002 12:12:53 -0000
- Subject: optimization/9041: gcc 3.2.1: inconsistent behaviour with/without -O2
- Reply-to: mia at de dot uu dot net
>Number: 9041
>Category: optimization
>Synopsis: gcc 3.2.1: inconsistent behaviour with/without -O2
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Dec 23 04:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Michael van Acken
>Release: gcc version 3.2.1
>Organization:
>Environment:
OS: Linux 2.4.19
CPU: Athlon-XP 1800+
>Description:
Output of program should be
1065353216
but it is
134518336
not equal
with -O2 (at least for me).
#include <stdio.h>
int main() {
float y = 1.0f;
int i = *(int*)&y;
printf("%d\n", i);
if (({int x = i; *(float*)&x;}) != 1.0f) {
printf("not equal\n");
};
return 0;
}
>How-To-Repeat:
~/local/bin/gcc -Wall -O2 Val5.c && ./a.out
>Fix:
Remove -O2. Add -march=athlonxp. Run gcc-2.95 with -O2.
And, most interestingly: Remove the "if" statement before the
return. All these variants give the expected result.
>Release-Note:
>Audit-Trail:
>Unformatted: