This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: label reference missed
On Fri, Aug 23, 2002 at 10:04:38AM -0400, Daniel Jacobowitz wrote:
> On Thu, Aug 22, 2002 at 09:21:00PM -0700, Zack Weinberg wrote:
> > On Thu, Aug 22, 2002 at 08:38:36PM -0700, Ulrich Drepper wrote:
> > > asm volatile ("jmp %0"::"m" (*&&fff));
> >
> > Not so simple; the optimizer would also have to be able to synthesize
> > an edge from the asm to the label, and in general this could be quite
> > difficult.
>
> I like your counterprosal better anyway, but I've got a question on the
> above - why is it difficult? If the asm is somewhere that a jump to
> the label would normally be allowed...
First, I suspect there is a lot of existing code that assumes that
an ASM_INPUT or ASM_OPERANDS RTL cannot appear except inside a plain
INSN; i.e. that it can't accomplish a transfer of control. I could be
wrong, but I am not particularly eager to try to find out.
More fundamentally, you are explicitly allowed to do address
arithmetic on the value of an &&label expression. I believe the only
current assumption the compiler makes about 'goto *assigned_label' is
that control transfers via an abnormal edge to *some* label in scope
whose address is taken. It needn't even be in the same function -
int a(void) {
void nested(void *x) {
goto *x;
}
nested(&&target);
return 0;
target:
return 1;
}
is accepted without complaint by both gcc 2.95 and gcc 3.2 (and
thoroughly miscompiled by both, but that's beside the point). We
would have to make the same assumptions about an asm() with a label as
one argument. It could be done, but is unlikely to be as optimizable
as Ulrich would probably like.
Worse still, consider
foo()
{
void *l;
/* pages of tangled code here... */
asm volatile ("jmp %0" : : "m" (label));
/* more tangled code... */
label:
/* not done yet... */
}
where, somewhere in the tangle, are several different conditional
initializations of "l" -- not necessarily all to the addresses of
labels. How does it know that the asm jumps at all? If it does,
where does it end up? I bet the halting problem's lurking in here
somewhere.
zw