[fpc-devel] Data flow analysis (dfa) and "case ... of"
fpc at mfriebe.de
Thu Jun 29 14:26:46 CEST 2017
On 28/06/2017 20:03, Martok wrote:
> Interestingly, I just ran into "bad" code generation with exactly the properties
> discussed in this thread.
> Because every declared element is covered, the generated code for it ends up
> being a computed goto:
> and most importantly, not into any else statement.
No, it is not bad code generation.
It is exactly the expected result. At least that is what I understood
from previous mails in this thread, specifically (in the context of
> Jonas Maebe wrote:
>> That is why I said "If range checking is off there or disabled via an
>> explicit type cast, then the result is undefined by definition."
"undefined result" does include the possibility of a crash.
This is the same as accessing an
Array[enum] of foo;
if enum is out of range, then it may crash, or behave in any undefined way.
The only thing that could be added here is, that if dfa detects that all
enums are used in a case statement, and yet there is an "else", then it
should warn about "unreachable code".
More information about the fpc-devel