How to get IfStmt for branch condition being checked in Clang Static Analyzer

let’s say I have a code snippet here :


Is there a way to get the if statement while checking the branch condition a==b in clang static anlayzer?

I have found an approach that works fine :

void checkBranchCondition(const Stmt * Condition, CheckerContext &C){
    auto* CFG = C.getAnalysisManager().getCFG(C.getLocationContext()->getDecl());
    const IfStmt* reqIF;
    for(auto i = CFG.begin(); i != CFG.end(); i++){
        auto *terminator = (*i)->getTerminatorStmt();
        if(!terminator) continue;
        if(!isa<IfStmt>(terminator)) continue;
        auto* ifStmt = dyn_cast_or_null<IfStmt>(terminator);
        if(ifStmt->getCond() == Condition){
            reqIF = ifStmt; break;
    // rest of the code

I would appreciate a better way. Thanks.