------- Comment #6 from wvangulik at xs4all dot nl  2008-01-20 19:30 -------
Bug is still present in 4.2.2.

Some more info:

I rewrote the example to (atleast for me) little more clear example.

struct fseqp_void
{
    void (*p) (void);
    char *e;
};

struct fseqp_void c;

void bar (void){}

int main (void)
{
    c.e = (char *)bar + 2;
    c.p = bar;
    c.p();
    return 0;
}

The problem is the re-use after loading bar into the struct:

        ldi r24,lo8(bar+2)          <<Hmm this should need gs() I guess
        ldi r25,hi8(bar+2)
        sts (c+2)+1,r25
        sts c+2,r24
        sbiw r24,2                  <<Sub 2, but we also need a shift!
        sts (c)+1,r25
        sts c,r24

However if comment out the dump the load off the variable e, then all is well

int main (void)
{
    //c.e = (char *)bar + 2;
    c.p = bar;
    c.p();
    return 0;
}

        ldi r24,lo8(gs(bar))
        ldi r25,hi8(gs(bar))
        sts (c)+1,r25
        sts c,r24
        ldi r24,lo8(0)
        ldi r25,hi8(0)

And if the order of assigment is reverted then all is well also

    c.e = (char *)bar + 2;
    c.p = bar;
    c.p();
    return 0;

        ldi r24,lo8(gs(bar))
        ldi r25,hi8(gs(bar))
        sts (c)+1,r25
        sts c,r24
        adiw r24,2
        sts (c+2)+1,r25
        sts c+2,r24
        ldi r24,lo8(0)
        ldi r25,hi8(0)

So the problem is the optimizer, which forget that the 16-bit program address
is different from the data address.


-- 

wvangulik at xs4all dot nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wvangulik at xs4all dot nl


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

Reply via email to