propagating checker state for duration of a block

hello

i am trying to write a checker that needs to propagate state for the duration of the branch blocks. can anyone suggest a good pattern for this? i can easily set state in the checkBranchCondition callback, but there does not seem to be any way to know when the branch block is complete, so it is not possible to know when to clear the state. ideally there would be a checkBlockEdge callback or something similar, then i could associate the state with the block id and it would be simple to know when to clear it. i cannot use the branch condition symbol as the state key as it will be purged as soon as the block starts.

is there already a way to do this that i am missing?

thanks

Hm. The analyzer sort of deliberately doesn't make it easy to do that, because of the (rough) equivalence of examples like this:

if (foo) {
  doSomething();
}

if (!foo) {
} else {
  doSomething();
}

if (!foo)
  return;
doSomething();

And you don't want to just use the block ID because of this:

if (foo) {
  if (bar) {
    doSomething();
  } else {
    doSomethingElse();
  }
}

For what it's worth, clearing out the state is generally just an optimization. If you don't do it, the analyzer will just continue analyzing the rest of the program along both paths (where the branch was true and where it was false).

What are you actually trying to do?

Jordan

well, the idea is to set state if a branch condition is checking for availability, eg

if ([foo respondsToSelector:@selector(onlyAvailableInIOS6:)]) {
  // set availability version
  doIOS6Stuff();
else {
  // issue a warning here
  doIOS6Stuff();
}

so a warning can be issued if there is are any methods used newer than the minimum deployment target that are being used without checking for their availability.

clearly here the state has to be cleared at the end of if {}, otherwise the checker will just assume that all successive calls in the graph have checked for availability already. what would you suggest as a good way of clearing the state once the ifstmt is complete?

well, the idea is to set state if a branch condition is checking for availability, eg

if ([foo respondsToSelector:@selector(onlyAvailableInIOS6:)]) {
// set availability version
doIOS6Stuff();
else {
// issue a warning here
doIOS6Stuff();
}

so a warning can be issued if there is are any methods used newer than the minimum deployment target that are being used without checking for their availability.

clearly here the state has to be cleared at the end of if {}, otherwise the checker will just assume that all successive calls in the graph have checked for availability already. what would you suggest as a good way of clearing the state once the ifstmt is complete?

Well, no, it doesn’t have to be. If I write this:

if ([foo respondsToSelector:@selector(onlyAvailableInIOS6:)]) {
doIOS6Stuff();
}

doMoreIOS6Stuff();

The call to ‘doMoreIOS6Stuff’ will be analyzed twice: once along the true-path from the if-statement, and once along the false-path. So you’d still get a warning on the false path, even though the true path would be quiet. And this is actually what you want for the early return case:

you are right of course, not thinking correctly. that makes things a lot easier.