This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/14299] New: Improperly derefences pointers with casting


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

-- 
           Summary: Improperly derefences pointers with casting
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dmeggy at techsol dot ca
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-linux
  GCC host triplet: i386-linux
GCC target triplet: arm-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14299


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]