[StaticAnalyzer] What is the right callback for analyzing IfStmt ?


I am hoping to be able to develop (and contribute) a checker from the "potential future checkers" at clang-analyzer.llvm.org. Currently, I have created a checker and successfully registered it with the analyzer, but it currently does nothing.

I have looked at the "potential future checkers" list, and thought the different.IdenticalCondIfElseIf item could be an easy checker to implement for a beginner (If I'm wrong, perhaps you could point me towards a checker that is easy to implement).

However, I don't know what callback to use, since checkPreStmt and checkPostStmt does not include control flow statements, and the checkBranchCondition only checks each branch condition.

I would need to examine the entire if-branch (if condition x every else if condition), to be able to detect identical branch conditions, right?

Mats Taraldsvik

Hi, Mats. You're right that there's currently not a pre-statement check for "if". However, the different.IdenticalCondIfElseIf checker probably does not need to use path-sensitive checks. Instead, you can use a syntactic check that simply walks the AST for a function body.

Actually, you should probably talk to Per Viberg, whose IdenticalExprChecker (identical expressions on both sides of a logical operator) is set to land soon. (Per, I'm going to check the results from LLVM/Clang today.) I imagine you'd be able to get a lot of reuse out of his code.