Bug 14299 - Improperly derefences pointers with casting
Summary: Improperly derefences pointers with casting
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-25 14:49 UTC by dmeggy
Modified: 2005-07-23 17:19 UTC (History)
1 user (show)

See Also:
Host: i386-linux
Target: arm-linux
Build: i386-linux
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 dmeggy 2004-02-25 14:50:00 UTC
Here is an example

<snip>
typedef struct
{
        unsigned first  : 6;
        unsigned second : 1;
        unsigned third  : 1;
        unsigned fourth : 1;
        unsigned fifth  : 1;
        unsigned sixth  : 1;
        unsigned unused : 21;
} TestStruct;

int func() {
        TestStruct a;
        TestStruct *b;

        a.first = 4;
        b = (TestStruct *)(&a);

        return b->first;
}

int func2() {
        int a;
        TestStruct *b;

        a = 4;
        b = (TestStruct *)(&a);

        return b->first;
}
</snip>

func() will work, and func2() won't, called as "arm-linux-gcc test2.c -Os -g -c"

func2 will never set the value of a to 4
Comment 1 Falk Hueffner 2004-02-25 14:52:18 UTC
The code violates aliasing rules and is therefore invalid. Newer gcc's even
warn about it.
Comment 2 Andrew Pinski 2005-06-05 03:10:38 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-06-05 03:10:54 UTC
Mark as a dup of bug 21920

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