[Bug optimization/14562] Incorrect loop code caused by pass_ch

fjahanian at apple dot com gcc-bugzilla@gcc.gnu.org
Fri Mar 12 22:22:00 GMT 2004


------- Additional Comments From fjahanian at apple dot com  2004-03-12 22:22 -------
Here is an executable test case:

typedef struct TypHeader {
    unsigned long size;
    struct TypHeader * * ptr;
} * TypHandle;

void gorf (unsigned long h, unsigned long k, TypHandle hdRes, TypHandle hdTmp)
{
    while ( hdTmp < ((hdRes)->ptr)[k-h] ) {
         ((hdRes)->ptr)[k] = ((hdRes)->ptr)[k-h];
         k = k-h;
    }
}

int main()
{
        int i;
        struct TypHeader* arrTypHeader[6];
        TypHandle hdTmp;

        struct TypHeader hd;
        hd.ptr = arrTypHeader;

        for (i=0; i < 6; i++)
        {
           arrTypHeader[i] = (struct TypHeader*)malloc(sizeof(struct TypHeader));
           arrTypHeader[i]->size = i;
        }

        gorf(1, 5, &hd, arrTypHeader[0]);
        for (i=0; i < 6; i++)
        {
           printf(" size = %d\n", arrTypHeader[i]->size);
        }

        return 0;
}

Compiled with -O0 produces following results:

 size = 0
 size = 1
 size = 1
 size = 2
 size = 3
 size = 4


Compiled with -O1 produces incorrect results:

 size = 0
 size = 1
 size = 2
 size = 3
 size = 4
 size = 5

-- 


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



More information about the Gcc-bugs mailing list