Direct recursion detection possible?
Cecil Ward
cecil at cecilward.com
Wed May 24 23:04:53 UTC 2023
Due to some stupidity of mine involving misuse of templates I
ended up with a routine that simply called itself infinitely.
Directly, that is, and in this case the routine was optimised
down into a simple infinite loop with no loop body content.
Is it possible for our compilers to detect direct infinite
recursion ? I’m ignoring the indirect call case, and I’m also
ignoring anything involving function pointers, so given those
restrictions, we will be able to see that the generated code of a
routine is calling its own address, because that address is a
literal and we know what the current function is that we’re
currently in.
And while we’re at it, is it possible to detect all kinds of
straightforward infinite loops (not coming from recursion)? That
is where the generated code, perhaps as a result of optimisation,
is a straight loop with no body. Can we implement that?
It ought to be possible because the backend can spot a pattern
like "L1: jmp L1".
I promise I’m not trying to solve the Halting Problem :)
Cecil Ward.
More information about the Digitalmars-d
mailing list