diff options
author | Balazs Benics <balazs.benics@sigmatechnology.se> | 2021-11-29 10:39:36 +0100 |
---|---|---|
committer | Balazs Benics <balazs.benics@sigmatechnology.se> | 2021-11-29 10:39:36 +0100 |
commit | af37d4b6fee8990d5b029796681b59e0d0390c28 (patch) | |
tree | 0088e8de5be8e855c2d6d5e5a97e618ecc51494c /clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | |
parent | 51e2c8c9bf96f19a3160a7da36be26943318a2cb (diff) | |
download | llvm-af37d4b6fee8990d5b029796681b59e0d0390c28.zip llvm-af37d4b6fee8990d5b029796681b59e0d0390c28.tar.gz llvm-af37d4b6fee8990d5b029796681b59e0d0390c28.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 31de490..f692c68 100644 --- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -591,16 +591,24 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) { // - Main source file: run both path-sensitive and non-path-sensitive checks. // - Header files: run non-path-sensitive checks only. // - System headers: don't run any checks. - SourceManager &SM = Ctx->getSourceManager(); - const Stmt *Body = D->getBody(); - SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation(); - SL = SM.getExpansionLoc(SL); - - if (!Opts->AnalyzeAll && !Mgr->isInCodeFile(SL)) { - if (SL.isInvalid() || SM.isInSystemHeader(SL)) - return AM_None; + if (Opts->AnalyzeAll) + return Mode; + + const SourceManager &SM = Ctx->getSourceManager(); + + const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation { + const Stmt *Body = D->getBody(); + SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation(); + return SM.getExpansionLoc(SL); + }(D); + + // Ignore system headers. + if (Loc.isInvalid() || SM.isInSystemHeader(Loc)) + return AM_None; + + // Disable path sensitive analysis in user-headers. + if (!Mgr->isInCodeFile(Loc)) return Mode & ~AM_Path; - } return Mode; } |