[cfe-dev] Best way to determine which condition branch i am on in a static analyzer checker

Jordan Rose jordan_rose at apple.com
Wed Dec 12 09:30:17 PST 2012


Well, if you're already using ParentMap, you could see if the Stmt just below the IfStmt represents the "then" statement or the "else" statement. (Or neither, if it's the condition!) However, if you've seen our talk, you'll remember that pattern-matching against statement kinds isn't the best way to determine control flow or assumptions:

- The user could have used "while" or "?:" instead of "if".
- There could be a goto or longjmp involved.
- You may be within an inlined function which is itself within an "if".
- Someone may have used an early return (or break or continue) instead of putting the rest of the block in an else-clause.

So, what are you actually trying to achieve?
Jordan


On Dec 12, 2012, at 8:06 , Richard <tarka.t.otter at googlemail.com> wrote:

> hey there
> 
> i am writing a static analyzer checker that needs to know if it is contained in a surrounding IfStmt, and if the current node is on the true or false branch. what is the simplest way to achieve this? 
> 
> currently i am using the previous nodes ParentMap and walking back up through parents until i find an IfStmt, but i am unsure how i can tell if this node belongs to the If or an Else / Else If branch. any pointers?
> 
> ta
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121212/584421c9/attachment.html>


More information about the cfe-dev mailing list