User account creation filtered due to spam.

Bug 11066 - error in the optimization of packed structures
Summary: error in the optimization of packed structures
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-02 17:44 UTC by jourgun
Modified: 2005-07-23 22:49 UTC (History)
1 user (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 jourgun 2003-06-02 17:44:33 UTC
error in the optimization of packed structures, when using -O2 or -O3.
preprossesor file:

# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "c:/djgpp/lib/gcc-lib/djgpp/3.23/djgpp.ver" 1
# 1 "c:/djgpp/include/sys/version.h" 1 3
# 2 "c:/djgpp/lib/gcc-lib/djgpp/3.23/djgpp.ver" 2
# 2 "<command line>" 2
# 1 "test.c"
unsigned long long GateDescriptor(Offset,Segment,TypeDPL,ParamCount)
         unsigned long Offset;
         unsigned short Segment;
         unsigned char TypeDPL,ParamCount;
         {
             typedef struct {
                    unsigned short Offset0_15;
                    unsigned short Segment;
                    unsigned char ParamCount;
                    unsigned char TypeDPL;
                    unsigned short Offset16_31;
             }Tdescripteur __attribute__ ((packed));

             Tdescripteur Descripteur;

             Descripteur.Offset0_15=Offset;
             Descripteur.Offset16_31=Offset>>16;
             Descripteur.Segment=Segment;
             Descripteur.TypeDPL=TypeDPL;
             Descripteur.ParamCount=ParamCount;

             return *(unsigned long long*)&Descripteur;
         }

int main(void){
 printf("%llX",GateDescriptor(0x65B,0x08,0xEF,0));
 getchar();
}

Normaly, we would see :
EF000008065B
but we see:
EF000000065B

the complete command line is:
gcc test.c -o test.exe -O2

I am working on DJGPP on Windows XP.
Comment 1 Andrew Pinski 2003-06-02 17:58:07 UTC
This is not a bug, you are violating ANSI/ISO C aliasing rules, you should be 
using an union.
Comment 2 Andrew Pinski 2005-06-05 08:23:56 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-06-05 08:24:13 UTC
Mark as a dup of bug 21920.

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