public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/9041: gcc 3.2.1: inconsistent behaviour with/without -O2
@ 2002-12-23  4:16 mia
  0 siblings, 0 replies; 2+ messages in thread
From: mia @ 2002-12-23  4:16 UTC (permalink / raw)
  To: gcc-gnats


>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:


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

* Re: optimization/9041: gcc 3.2.1: inconsistent behaviour with/without -O2
@ 2002-12-23  5:14 ebotcazou
  0 siblings, 0 replies; 2+ messages in thread
From: ebotcazou @ 2002-12-23  5:14 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mia, nobody

Synopsis: gcc 3.2.1: inconsistent behaviour with/without -O2

State-Changed-From-To: open->closed
State-Changed-By: ebotcazou
State-Changed-When: Mon Dec 23 05:14:33 2002
State-Changed-Why:
    Not a bug. Your code breaks the ISO C aliasing rules. Compile it with -O2 -fno-strict-aliasing instead.

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


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

end of thread, other threads:[~2002-12-23 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-23  4:16 optimization/9041: gcc 3.2.1: inconsistent behaviour with/without -O2 mia
2002-12-23  5:14 ebotcazou

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