summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2016-01-30 01:59:33 +0000
committerDevin Coughlin <dcoughlin@apple.com>2016-01-30 01:59:33 +0000
commit4be27d4db97ab48f2bb95143c6103145139296de (patch)
treebf782e7b0dbd85a26157b183880e85e9596a808b /clang/lib
parentb4030df780ad1fb72c372764cb582fe2287aa595 (diff)
downloadbcm5719-llvm-4be27d4db97ab48f2bb95143c6103145139296de.tar.gz
bcm5719-llvm-4be27d4db97ab48f2bb95143c6103145139296de.zip
[analyzer] Make suppression of macro defensive checks work with -analyzer-eagerly-assume.
This is the default for the analyzer but the flag is added by the driver so our suppression tests didn't cover this case. llvm-svn: 259288
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index f1c3223fae4..ae5cd546f8d 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -14,6 +14,7 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
+#include "clang/Analysis/CFGStmtMap.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
@@ -834,21 +835,41 @@ SuppressInlineDefensiveChecksVisitor::VisitNode(const ExplodedNode *Succ,
}
// Treat defensive checks in function-like macros as if they were an inlined
- // defensive check.
- auto CurPoint = Succ->getLocation().getAs<BlockEdge>();
+ // defensive check. If the bug location is not in a macro and the
+ // terminator for the current location is in a macro then suppress the
+ // warning.
auto BugPoint = BR.getErrorNode()->getLocation().getAs<StmtPoint>();
- if (!CurPoint || !BugPoint)
+ if (!BugPoint)
return nullptr;
- SourceLocation CurLoc =
- CurPoint->getSrc()->getTerminator().getStmt()->getLocStart();
SourceLocation BugLoc = BugPoint->getStmt()->getLocStart();
+ if (BugLoc.isMacroID())
+ return nullptr;
+
+ ProgramPoint CurPoint = Succ->getLocation();
+ const Stmt *CurTerminatorStmt = nullptr;
+ if (auto BE = CurPoint.getAs<BlockEdge>()) {
+ CurTerminatorStmt = BE->getSrc()->getTerminator().getStmt();
+ } else if (auto SP = CurPoint.getAs<StmtPoint>()) {
+ const Stmt *CurStmt = SP->getStmt();
+ if (!CurStmt->getLocStart().isMacroID())
+ return nullptr;
+
+ CFGStmtMap *Map = CurLC->getAnalysisDeclContext()->getCFGStmtMap();
+ CurTerminatorStmt = Map->getBlock(CurStmt)->getTerminator();
+ } else {
+ return nullptr;
+ }
+
+ if (!CurTerminatorStmt)
+ return nullptr;
- if (CurLoc.isMacroID() && !BugLoc.isMacroID()) {
+ SourceLocation TerminatorLoc = CurTerminatorStmt->getLocStart();
+ if (TerminatorLoc.isMacroID()) {
const SourceManager &SMgr = BRC.getSourceManager();
- std::pair<FileID, unsigned> CLInfo = SMgr.getDecomposedLoc(CurLoc);
- SrcMgr::SLocEntry SE = SMgr.getSLocEntry(CLInfo.first);
+ std::pair<FileID, unsigned> TLInfo = SMgr.getDecomposedLoc(TerminatorLoc);
+ SrcMgr::SLocEntry SE = SMgr.getSLocEntry(TLInfo.first);
const SrcMgr::ExpansionInfo &EInfo = SE.getExpansion();
if (EInfo.isFunctionMacroExpansion()) {
BR.markInvalid("Suppress Macro IDC", CurLC);
OpenPOWER on IntegriCloud