In LLVM IR, how can I determine if a switch statement had an explicit default case?

Since a SwitchInst always has a default case even if no default case appeared in the code, what’s the best way to determine if it’s explicit or implicit?

thanks…
don

Hi Don,

Hi Tim:

That’s essentially what I came up with too, but was hoping there might be an existing analysis pass that could be helpful.

I’m writing a tool that can inject faults at runtime to increase code coverage, e.g, based on gcov results. It supports branch (if only) and switch instructions, but currently ignores branches associated with loops, though I hope to add some support for non-range based loops at some point.

If I could determine that the default case is implicit, I could ignore it at compile time. Otherwise, it’s included in the list of candidates and only gets excluded at runtime based on coverage. Also, determining the correct fault value to inject for the default case must be calculated, which isn’t as easy as using ICmpInst::makeConstantRange for if branches.

thanks…
don

Hi Tim:

Actually, after thinking about it a bit more, I really can’t exclude the default case even if it is implicit. If the block after the switch is never covered, and doesn’t have an unreachable instruction, I should really try to cover it as well.

As always, explaining the problem helped.

thanks again…
don