This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/27192] call through function pointer goes to wrong address
- From: "wvangulik at xs4all dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Jan 2008 19:30:33 -0000
- Subject: [Bug target/27192] call through function pointer goes to wrong address
- References: <bug-27192-12544@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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