Bug 21642 - [3.4 Regression] wrong code with -O2
Summary: [3.4 Regression] wrong code with -O2
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.6
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-05-18 10:01 UTC by Jörg Richter
Modified: 2006-02-28 10:19 UTC (History)
1 user (show)

See Also:
Host: powerpc-ibm-aix5.2.0.0
Target: powerpc-ibm-aix5.2.0.0
Build: powerpc-ibm-aix5.2.0.0
Known to work: 4.0.0 4.0.1 4.1.0
Known to fail: 3.4.3 3.4.4
Last reconfirmed: 2006-01-07 01:55:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Richter 2005-05-18 10:01:13 UTC
$ gcc -v 
Reading specs from /pdv/.tools/pkg/gcc/3.4.3/bin/../lib/gcc/powerpc-ibm-
aix5.2.0.0/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/tools/pkg/gcc/3.4.3 --with-
ld=/bin/ld --with-as=/bin/as --disable-threads --enable-languages=c,c++
Thread model: aix
gcc version 3.4.3

// foo.c //

#include <stdio.h>

inline void
reverse( char* beg, char* end )
{
  while( beg < --end )
  {
    char t = *end;
    *end = *beg;
    *beg++ = t;
  }
}

void doIt( int* val )
{
  reverse( (char*)val, (char*)val + sizeof( *val ) );
}

int main()
{
  int d = 0x12345678;
  printf( "%x\n", d );
  doIt( &d );
  printf( "%x\n", d );
  return 0;
}

////

$ gcc -o foo foo.c -O2
$ foo
12345678
78345612

$ gcc -o foo foo.c
$ foo
12345678
78563412

Works with GCC 3.3.3
Comment 1 David Edelsohn 2005-06-06 15:17:13 UTC
This appears to be related to strength reduction.

-O2 -fno-strength-reduce succeeds
-O1 -fstrength-reduce fails.

The bug is not present in GCC 4.
Comment 2 Gabriel Dos Reis 2006-02-28 10:19:10 UTC
won't fix for 3.4.6