12#include "llvm/Support/FormatVariadic.h"
13#include "llvm/Support/TimeProfiler.h"
22inline bool hasSuppression(
const Decl *
D) {
25 if (
const auto *Suppression =
D->
getAttr<SuppressAttr>())
26 return !Suppression->isGSL() &&
27 (Suppression->diagnosticIdentifiers().empty());
33 return llvm::any_of(S->getAttrs(), [](
const Attr *A) {
34 const auto *Suppression = dyn_cast<SuppressAttr>(A);
35 return Suppression && !Suppression->isGSL() &&
36 (Suppression->diagnosticIdentifiers().empty());
64 return !
SM.isBeforeInTranslationUnit(RHS, LHS);
84 CacheInitializer(ToInit).TraverseDecl(
const_cast<Decl *
>(
D));
92 return VisitAttributedNode(
D);
99 return VisitAttributedNode(AS);
103 template <
class NodeType>
bool VisitAttributedNode(NodeType *
Node) {
104 if (hasSuppression(
Node)) {
120 CacheInitializer(Ranges &R) : Result(R) {}
124std::string timeScopeName(
const Decl *DeclWithIssue) {
125 if (!llvm::timeTraceProfilerEnabled())
127 return llvm::formatv(
128 "BugSuppression::isSuppressed init suppressions cache for {0}",
133llvm::TimeTraceMetadata getDeclTimeTraceMetadata(
const Decl *DeclWithIssue) {
134 assert(DeclWithIssue);
135 assert(llvm::timeTraceProfilerEnabled());
136 std::string Name =
"<noname>";
137 if (
const auto *ND = dyn_cast<NamedDecl>(DeclWithIssue)) {
138 Name = ND->getNameAsString();
141 auto Line =
SM.getPresumedLineNumber(DeclWithIssue->
getBeginLoc());
143 return llvm::TimeTraceMetadata{std::move(Name), Fname.str(),
144 static_cast<int>(Line)};
164 const Decl *DeclWithIssue,
169 if (!DeclWithIssue) {
184 if (
Parent ==
nullptr || isa<TranslationUnitDecl>(
Parent))
201 auto InsertionResult = CachedSuppressionLocations.insert(
203 Ranges &SuppressionRanges = InsertionResult.first->second;
204 if (InsertionResult.second) {
205 llvm::TimeTraceScope TimeScope(
206 timeScopeName(DeclWithIssue),
207 [DeclWithIssue]() {
return getDeclTimeTraceMetadata(DeclWithIssue); });
209 CacheInitializer::initialize(DeclWithIssue, SuppressionRanges);
215 return llvm::any_of(SuppressionRanges,
217 return fullyContains(Suppression, BugRange,
SM);
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
const char * getDeclKindName() const
SourceLocation getBeginLoc() const LLVM_READONLY
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
SourceRange getSourceRange(bool IncludeQualifier=false) const
For nodes which represent textual entities in the source code, return their SourceRange.
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool VisitDecl(MaybeConst< Decl > *D)
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
This class provides an interface through which checkers can create individual bug reports.
virtual PathDiagnosticLocation getUniqueingLocation() const =0
Get the location on which the report should be uniqued.
virtual PathDiagnosticLocation getLocation() const =0
The primary location of the bug report that points at the undesirable behavior in the code.
virtual const Decl * getDeclWithIssue() const =0
The smallest declaration that contains the bug location.
bool isSuppressed(const BugReport &)
Return true if the given bug report was explicitly suppressed by the user.
PathDiagnosticRange asRange() const
const SourceManager & getManager() const
The JSON file list parser is used to communicate input to InstallAPI.
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
@ Result
The result type of a method or function.