Not sure i'm missing something about the use of goto
:
This doesnt work, ends in a segfault:
for(long i = 0; i < 1000000000; i++) {
LABEL_1: {
int test[10];
goto LABEL_2;
}
LABEL_2: {
int test[10];
}
}
Whereas this works:
for(long i = 0; i < 1000000000; i++) {
LABEL_1: {
{ // Note this extra block
int test[10];
}
goto LABEL_2;
}
LABEL_2: {
int test[10];
}
}
This examples dont trigger the issue, but represent what is happening in my code.
This is a simplified example of what is happening in https://github.com/risotto/risotto/tree/feature/direct-threading-2
See https://github.com/risotto/risotto/blob/feature/direct-threading-2/src/lib/vm/vm.c#L332 and https://github.com/risotto/risotto/blob/feature/direct-threading-2/src/lib/vm/vm.c#L257
From my repo, this works:
case TARGET(OP_RETURN):
{
FunctionCall fc = vec_pop(&vm.fcs);
int rc = fc.retc;
{
Value rvals[rc];
for (int i = rc - 1; i >= 0; --i) {
rvals[i] = copy(pop());
}
vm.ip = fc.ip;
vm.sp = fc.sp;
vm.fp = fc.fp;
vm.sp -= fc.argc;
pushm(rvals, rc);
}
NEXT();
}
This doesnt:
case TARGET(OP_RETURN):
{
FunctionCall fc = vec_pop(&vm.fcs);
int rc = fc.retc;
Value rvals[rc];
{
for (int i = rc - 1; i >= 0; --i) {
rvals[i] = copy(pop());
}
vm.ip = fc.ip;
vm.sp = fc.sp;
vm.fp = fc.fp;
vm.sp -= fc.argc;
pushm(rvals, rc);
}
NEXT();
}
This is compiled through gcc GNU 7, and makes use of computed goto inside NEXT