I use Polyspace IHME-8.1.0.12 (R2011a) to find dead code in my project. Currently, the analysis catches this case:
int f1() {
int x = 1;
if (x > 0) return 1;
else return 0; // dead code
}
But not this case:
int f2(int x) {
if (x > 0) return 1;
else return 0; // the very same dead code!
}
void call_site() {
f2(1);
}
Note that x
became a parameter, but it still has a constant value, 1
. The funciton f2()
is called only by call_site()
, or, alternatively, every call site calls f2()
with x=1
.
Is there a configuration option I should activate to analyse all call sites when looking for unreachable code? Or is this a limitation of Polyspace?
Can you tell me if there is a main in the application? If not, then Polyspace will use its main generator and so may also call f2 (it depends on how the main generator is configured). And if f2 is called also by the main generator, then x is considered to take any value. You can see the range of x that Polyspace is considering if you look at the tooltip on x or if you click on x and take a look at the check details window.