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

Jordan Rose jordan_rose at apple.com
Wed Dec 11 10:08:55 PST 2013


On Dec 6, 2013, at 10:07 , Zach Davis <zdavkeos at gmail.com> wrote:

> > Right; what I meant was that we'd prefer to make this work rather than adding switch statements to checkBranchCondition, but right now neither one works. Sorry for the inconvenience.
> > 
> > Jordan
> 
> I had this same problem and ended up using an ast-matcher in a clang tool instead to get the information I wanted.
> 
> I would be interested in helping add this feature though.
> 
> 
> I found the bug report (18175), but could use some pointers to get started on a patch.

Hi, Zach. That's great to hear. The code lives in ExprEngine.cpp, and you can see in functions like ExprEngine::VisitUnaryOperator (ExprEngineC.cpp) that it basically just consists of a call to the CheckerManager to run the pre-statement checks, then a loop over the results to actually perform the evaluation. In ExprEngine::processBranch the loop is already in place, so you just need to add the second callback; ExprEngine::processSwitch also has a loop but may need a bit more restructuring. ExprEngine::processIndirectGoto is the last of these and probably needs a completely new loop added.

Please feel free to ask more specific questions, and when you're ready send the first iteration of your patch to cfe-commits.

Thanks for picking this up!
Jordan



More information about the cfe-dev mailing list