avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] avr-gcc 3.4.3 confused about function pointers


From: John Regehr
Subject: [avr-gcc-list] avr-gcc 3.4.3 confused about function pointers
Date: Sun, 16 Apr 2006 15:55:44 -0600
User-agent: Thunderbird 1.5 (Windows/20051201)

I'm attaching a program that avr-gcc 3.4.3 miscompiles. The bug is nasty and results in indirect calls to neverneverland.

Compiling like this:

  avr-gcc -Wall -mmcu=atmega128 -Os foo.c

gives a program that icalls to a bad address.

On the other hand, compiling the same program with -O instead of -Os
results in correct code.

The problem occurs when the Z register is loaded with the address of
foo().  In the buggy (-Os) version, the literal address of foo() is
loaded, rather than the address shifted right by one bit position. With -O the compiler gets it right.

I'd appreciate hearing about it if there's a patch for this or if the bug is known to be fixed in later versions.

Thanks,

John Regehr
struct bar
{
    void *yyy;
    void *aaa;
};

void foo (void)
{
}

void stuff (void)
{
    struct bar back[2];

    void (*p) (void) = foo;

    back[0].aaa = (void *) (&foo + 1);
    
    int i;
    for (i=0; i<6; i++) {
        back[0].aaa = back[0].yyy;
    }
    
    (*p)();
}   

int
main (void)
{
    stuff ();
    return 0;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]