Skip to content

Commit af37d4b

Browse files
author
Balazs Benics
committed
[analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()
I just read this part of the code, and I found the nested ifs less readable. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D114441
1 parent 51e2c8c commit af37d4b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,16 +591,24 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) {
591591
// - Main source file: run both path-sensitive and non-path-sensitive checks.
592592
// - Header files: run non-path-sensitive checks only.
593593
// - System headers: don't run any checks.
594-
SourceManager &SM = Ctx->getSourceManager();
595-
const Stmt *Body = D->getBody();
596-
SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
597-
SL = SM.getExpansionLoc(SL);
598-
599-
if (!Opts->AnalyzeAll && !Mgr->isInCodeFile(SL)) {
600-
if (SL.isInvalid() || SM.isInSystemHeader(SL))
601-
return AM_None;
594+
if (Opts->AnalyzeAll)
595+
return Mode;
596+
597+
const SourceManager &SM = Ctx->getSourceManager();
598+
599+
const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
600+
const Stmt *Body = D->getBody();
601+
SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
602+
return SM.getExpansionLoc(SL);
603+
}(D);
604+
605+
// Ignore system headers.
606+
if (Loc.isInvalid() || SM.isInSystemHeader(Loc))
607+
return AM_None;
608+
609+
// Disable path sensitive analysis in user-headers.
610+
if (!Mgr->isInCodeFile(Loc))
602611
return Mode & ~AM_Path;
603-
}
604612

605613
return Mode;
606614
}

0 commit comments

Comments
 (0)