You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int f1(a) inline {
if (a > -1) {
return 3;
}
return 2;
}
int main() {
return 1 + f1(2);
}
will be compiled into
PROGRAM{
DECLPROC f1
DECLPROC main
f1 PROC:<{
// a
-1 GTINT // _2
IFJMP:<{ //
3 PUSHINT // _3=3
}> //
2 PUSHINT // _4=2
}>
main PROC:<{
//
2 PUSHINT // _1=2
f1 INLINECALLDICT // _2
INC // _3
}>
}END>c
and upon execution <b b> 0 "some.fif" include <s <b b> runvm 2drop swap drop
will return 3 instead of 4.
This bug happens due to the fact that funC compiler inserts IFJMP for ifs with returns (in f1 in example above) and being inlined IFJMP jumps out not from the function it caused (f1) but from the function which inlined function with if (main).
There are two approaches to combat this behavior:
detect on funC level that function is inlined and do not use IFJMPs in that case
redefine INLINECALLDICT such it will wrap inline functions into PUSHCONT { ... } EXECUTE (this will, however, consume excessive space even for the cases when it is not necessary).
The text was updated successfully, but these errors were encountered:
The following code
will be compiled into
and upon execution
<b b> 0 "some.fif" include <s <b b> runvm 2drop swap drop
will return 3 instead of 4.
This bug happens due to the fact that funC compiler inserts
IFJMP
for ifs with returns (inf1
in example above) and being inlinedIFJMP
jumps out not from the function it caused (f1
) but from the function which inlined function with if (main
).There are two approaches to combat this behavior:
PUSHCONT { ... } EXECUTE
(this will, however, consume excessive space even for the cases when it is not necessary).The text was updated successfully, but these errors were encountered: