Bug 33379 - Bad code generation with O3
Summary: Bad code generation with O3
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-10 14:40 UTC by Tompa Laszlo
Modified: 2007-09-10 16:04 UTC (History)
17 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tompa Laszlo 2007-09-10 14:40:55 UTC
Hello ,

this code below compiles with different results.
with -O0 the result is 1.(expected res.)
from -O2 (and above) the result is 0.(BUG!)  

Thank You !


include<stdio.h>

#ifdef _BIG_ENDIAN
#define FP_SEG(fp) (*((unsigned short*)&(fp)))
#define FP_OFF(fp) (*((unsigned short*)&(fp)+1))
#else
#define FP_SEG(fp) (*((unsigned short*)&(fp)+1))
#define FP_OFF(fp) (*((unsigned short*)&(fp)))
#endif

#define BYTE unsigned char
#define _huge

unsigned short int zHugeOffset;


int main(){


        BYTE _huge *phb;

        unsigned short int selBit;


        FP_SEG(phb)=0; FP_OFF(phb)=0xffff; phb+=0x8000; selBit=FP_SEG(phb);


        zHugeOffset=selBit;

        printf("RESULT :%hd\n", zHugeOffset);


}
Comment 1 Andrew Pinski 2007-09-10 14:44:53 UTC
You are violating C/C++ aliasing rules.  You are accessing a "unsigned char*" as a "unsigned short".

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