Bug 11011 - get different result when optimization turned on on sparc/solaris
Summary: get different result when optimization turned on on sparc/solaris
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2003-05-28 08:10 UTC by Rick Ju
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Rick Ju 2003-05-28 08:10:31 UTC
get different result with -g and -O2 

this can be reproduced on 3.1 and 3.2. But gcc2.95.3 works fine.

how to reproduce:

 compile the attache main.c with -O2 and -g and observe the different output. It
 seems that the line with XXX would be ignored when compiled with -O2.



int func(short * psRow, short *pRecBlock)

    pRecBlock[0] = pRecBlock[0] + psRow[0]; 
    pRecBlock[1] = pRecBlock[1] + psRow[1]; 

    *(unsigned int *)&pRecBlock[0] -= 0x100100;   //XXX
    //pRecBlock[0] = pRecBlock[0] -  0x100;
    //pRecBlock[1] = pRecBlock[1] -  0x100;

    printf(" %x %x \n", pRecBlock[0], pRecBlock[1]);

int main(int argc, char** argv) {

  short psRow[10];
  short psRecBlock[10];

  memset(psRow, 0xffff, 10);
  memset(psRecBlock, 0, 10);

  func(psRow, psRecBlock);

  return 0;
Comment 1 Eric Botcazou 2003-05-28 08:32:27 UTC
Not a bug. The compiler is allowed to do so because your code, specifically the
line you pointed out, violates the ISO C aliasing rules. GCC automatically turns
on -fstrict-aliasing at -O2 so you need to fix your code or compile it with
Comment 2 Andrew Pinski 2005-06-05 08:22:54 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-06-05 08:23:16 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***