[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Forward: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc)



>                                            ÀéÍÕ»ÔÃæ±û¶èĹ½§
>                                                    Æ£¸¶  À¿
¤¢¤Î¸å¡¢¹¹¤ËÊÖ»ö¤ò½ñ¤¤¤Æ¡¢Îɤ¯¸«Ä¾¤·¤¿¤é printf ¤Î·ë²Ì¤¬¼«Ê¬¤Ç
ǼÆÀ½ÐÍè¤Ê¤¤¤â¤Î¤Ë¤Ê¤Ã¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡¢

¹¹¤ËÊÖ»ö¤ò¤â¤é¤Ã¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡£
http://gcc.gnu.org/cgi-bin/gnatsweb.pl
¤Ë view #:  7427
¤ÈÆþÎϤ¹¤ì¤Ð¸«¤¨¤ë¤â¤Î¤Î¤Ï¤º¤Ç¤¹¤¬....

---
(Æ£¸¶)


C aliasing rules say that variables with two different types do
not belong to the same alias set (except for char* and void*).

The correct way to fix the problem is using an union:

#include <stdio.h>

struct buf {
        int data;
};

union buf1 {
        struct buf buf1;
        unsigned short m[sizeof(struct buf)/sizeof(short)];
};

bug(m)
        struct buf *m;
{
        int sum = 0;
        union buf1 w;

        bzero(&w.buf1, sizeof tmp);
        w.buf1 = m->data;

        sum += w.m[0];
        sum += w.m[1];

        printf("sum = 0x%x\n", sum);

        return 0;
}

main()
{
        struct buf m;

        m.data = 0x12345678;
        bug(&m);
}

Thanks,
Andrew Pinski