[tree-ssa] Computed gotos
Paul Brook
paul@nowt.org
Sun Jun 15 17:46:00 GMT 2003
What is the proper method for handling computed gotos? In fortran we have
code which is equivalent to the following. I've not idea if this is
actually legal C, but it shows what I'm trying to achieve.
void test(int i)
{
static void *ptr[2] = {&label0, &label1}
goto ptr[i];
label0:
//do something
label1:
//do something else
}
A few questions:
Is void* the correct type for the address of a label?
I know some archetectures (ia64) have different types for function pointers.
Is the same true for labels local to a function?
How do I annotate the labels to mark them as the destination of a computed
goto statement? TREE_ADDRESSABLE doesn't have any noticable effect. I'd say
this would be the most obvious way of specifying that the label is the
target of an unknown goto.
Setting TREE_SIDE_EFFECTS seems to work but I'm not sure if this is
reliable. If I don't set TREE_SIDE_EFFECTS the optimizer decides neither of
the labels are used and removes them.
Is this kind of thing ever likely to work reliably and efficiently?
I could probably rearrange things so we end up with a switch statement
containing normal gotos. This would eliminate the need for indirect jumps
altogether. Maybe this is the way to go?
Paul
More information about the Gcc
mailing list