r259288 - [analyzer] Make suppression of macro defensive checks work with -analyzer-eagerly-assume.
Devin Coughlin via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 29 17:59:34 PST 2016
Author: dcoughlin
Date: Fri Jan 29 19:59:33 2016
New Revision: 259288
URL: http://llvm.org/viewvc/llvm-project?rev=259288&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/inlining/false-positive-suppression.c
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=259288&r1=259287&r2=259288&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Jan 29 19:59:33 2016
@@ -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::Vi
}
// 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);
Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.c?rev=259288&r1=259287&r2=259288&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.c (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.c Fri Jan 29 19:59:33 2016
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config suppress-null-return-paths=false -verify %s
-// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify -DSUPPRESSED=1 %s
-// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config avoid-suppressing-null-argument-paths=true -DSUPPRESSED=1 -DNULL_ARGS=1 -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-eagerly-assume -analyzer-checker=core -analyzer-config suppress-null-return-paths=false -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-eagerly-assume -analyzer-checker=core -verify -DSUPPRESSED=1 %s
+// RUN: %clang_cc1 -analyze -analyzer-eagerly-assume -analyzer-checker=core -analyzer-config avoid-suppressing-null-argument-paths=true -DSUPPRESSED=1 -DNULL_ARGS=1 -verify %s
int opaquePropertyCheck(void *object);
int coin();
@@ -145,14 +145,24 @@ int isEqual(int *p, int *q);
#define ISNOTEQUAL(a, b) (!ISEQUAL(a, b))
void testNestedDisjunctiveMacro(int *p, int *q) {
if (ISNOTEQUAL(p,q)) {
- (void)*p; // no-warning
- (void)*q; // no-warning
+ *p = 1; // no-warning
+ *q = 1; // no-warning
}
- (void)*p; // no-warning
- (void)*q; // no-warning
+ *p = 1; // no-warning
+ *q = 1; // no-warning
}
+void testNestedDisjunctiveMacro2(int *p, int *q) {
+ if (ISEQUAL(p,q)) {
+ return;
+ }
+
+ *p = 1; // no-warning
+ *q = 1; // no-warning
+}
+
+
// Here the check is entirely in non-macro code even though the code itself
// is a macro argument.
#define MACRO_DO_IT(a) (a)
More information about the cfe-commits
mailing list