[cfe-dev] : Clang Static Code Analyzer does not report 'Switch' Statement as a branch condition.

Jordan Rose jordan_rose at apple.com
Tue Dec 3 09:32:11 PST 2013


Hi, Prashant. check::BranchCondition is only intended to be used for boolean branches, since the first argument is the conditional expression used for branching.* With a switch statement, that no longer makes sense. That said, you're right that there's currently no callback for a switch statement. The right thing to do here is probably to run pre-statement checks on the terminator statement in the CFG when it's not a logical expression or conditional expression, so that the nomal check::PreStmt<SwitchStmt> would work.

Please file a bug at llvm.org/bugs/, or alternately submit a patch to cfe-commits at cs.uiuc.edu for review (and CC me or Anna).

Sorry for the trouble,
Jordan

* Implementation detail: it's a Stmt, not an Expr, because we stash the branch info for an Objective-C for-in loop on the loop statement itself. But it's still a boolean value.



On Nov 28, 2013, at 5:04 , Prashant Purohit <Prashant.Purohit at kpit.com> wrote:

> Hi all,
>  
> I am new to Clang Static Code analyzer internals.
>  
> Currently, I am trying to get all the branch conditions in a function using ‘check::BranchCondition’ call back function.
> I am successful in detecting all the branch conditions like if, while, do..while, for and ternary operator condition except switch condition.
>  
> I have checked this with already existing checks (e.g.- DumpTraversal) which uses ‘check::BranchCondition’ call back function, these checks
> also do not detect ‘switch’ statements.
>  
> Kindly help me in getting switch statements using ‘check::BranchCondition’ call back function.
>  
> Thanks,
> Prashant S. Purohit
> This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails. _______________________________________________
> 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/20131203/beab68fa/attachment.html>


More information about the cfe-dev mailing list