Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp =================================================================== --- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -841,6 +841,13 @@ return "IDCVisitor"; } +/// \return name of the macro inside the location \p Loc. +static StringRef getMacroName(SourceLocation Loc, + BugReporterContext &BRC) { + return Lexer::getImmediateMacroName( + Loc, BRC.getSourceManager(), BRC.getASTContext().getLangOpts()); +} + std::shared_ptr SuppressInlineDefensiveChecksVisitor::VisitNode(const ExplodedNode *Succ, const ExplodedNode *Pred, @@ -880,9 +887,6 @@ if (!BugPoint) return nullptr; - SourceLocation BugLoc = BugPoint->getStmt()->getLocStart(); - if (BugLoc.isMacroID()) - return nullptr; ProgramPoint CurPoint = Succ->getLocation(); const Stmt *CurTerminatorStmt = nullptr; @@ -909,7 +913,13 @@ SrcMgr::SLocEntry SE = SMgr.getSLocEntry(TLInfo.first); const SrcMgr::ExpansionInfo &EInfo = SE.getExpansion(); if (EInfo.isFunctionMacroExpansion()) { - BR.markInvalid("Suppress Macro IDC", CurLC); + SourceLocation BugLoc = BugPoint->getStmt()->getLocStart(); + + // Suppress reports unless we are in that same macro. + if (!BugLoc.isMacroID() || + getMacroName(BugLoc, BRC) != getMacroName(TerminatorLoc, BRC)) { + BR.markInvalid("Suppress Macro IDC", CurLC); + } return nullptr; } } Index: test/Analysis/inlining/false-positive-suppression.c =================================================================== --- test/Analysis/inlining/false-positive-suppression.c +++ test/Analysis/inlining/false-positive-suppression.c @@ -171,6 +171,15 @@ (void)i; } +// No warning should be emitted if dereference is performed from a different +// macro. +#define MACRO_CHECK(a) if (a) {} +#define MACRO_DEREF(a) (*a) +int testDifferentMacro(int *p) { + MACRO_CHECK(p); + return MACRO_DEREF(p); // no-warning +} + // -------------------------- // "Suppression suppression" // --------------------------