12#include "llvm/ADT/STLExtras.h"
13#include "llvm/Support/FormatVariadic.h"
14#include "llvm/Support/TimeProfiler.h"
23inline bool hasSuppression(
const Decl *D) {
26 if (
const auto *Suppression = D->
getAttr<SuppressAttr>())
27 return !Suppression->isGSL() &&
28 (Suppression->diagnosticIdentifiers().empty());
35 const auto *Suppression = dyn_cast<SuppressAttr>(A);
36 return Suppression && !Suppression->isGSL() &&
37 (Suppression->diagnosticIdentifiers().empty());
42 return Node->getSourceRange();
65 return !
SM.isBeforeInTranslationUnit(RHS, LHS);
84 static void initialize(
const Decl *D, Ranges &ToInit) {
85 CacheInitializer(ToInit).TraverseDecl(
const_cast<Decl *
>(D));
88 bool VisitDecl(Decl *D)
override {
93 return VisitAttributedNode(D);
96 bool VisitAttributedStmt(AttributedStmt *AS)
override {
100 return VisitAttributedNode(AS);
104 template <
class NodeType>
bool VisitAttributedNode(NodeType *Node) {
105 if (hasSuppression(Node)) {
115 void addRange(SourceRange R) {
121 CacheInitializer(Ranges &R) : Result(
R) {
122 ShouldVisitTemplateInstantiations =
true;
123 ShouldWalkTypesOfTypeLocs =
false;
124 ShouldVisitImplicitCode =
false;
125 ShouldVisitLambdaBody =
true;
130std::string timeScopeName(
const Decl *DeclWithIssue) {
131 if (!llvm::timeTraceProfilerEnabled())
133 return llvm::formatv(
134 "BugSuppression::isSuppressed init suppressions cache for {0}",
139llvm::TimeTraceMetadata getDeclTimeTraceMetadata(
const Decl *DeclWithIssue) {
140 assert(DeclWithIssue);
141 assert(llvm::timeTraceProfilerEnabled());
142 std::string Name =
"<noname>";
143 if (
const auto *ND = dyn_cast<NamedDecl>(DeclWithIssue)) {
144 Name = ND->getNameAsString();
149 return llvm::TimeTraceMetadata{std::move(Name), Fname.str(),
150 static_cast<int>(
Line)};
163 const Decl *DeclWithIssue = R.getDeclWithIssue();
201 PartialSpec = MemberPS;
209 for (
const auto *Redecl : Tmpl->redecls()) {
210 if (
const T *D =
cast<T>(Redecl); D->isThisDeclarationADefinition()) {
214 assert(
false &&
"This template must have a redecl that is a definition");
247 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
252 const auto *SpecializationDecl = dyn_cast<ClassTemplateSpecializationDecl>(D);
253 if (!SpecializationDecl)
256 auto InstantiatedFrom = SpecializationDecl->getInstantiatedFrom();
257 if (!InstantiatedFrom)
270 const Decl *DeclWithIssue,
272 if (!Location.isValid())
275 if (!DeclWithIssue) {
304 DeclWithIssue = Parent;
318 auto InsertionResult = CachedSuppressionLocations.insert(
319 std::make_pair(DeclWithIssue, CachedRanges{}));
320 Ranges &SuppressionRanges = InsertionResult.first->second;
321 if (InsertionResult.second) {
322 llvm::TimeTraceScope TimeScope(
323 timeScopeName(DeclWithIssue),
324 [DeclWithIssue]() {
return getDeclTimeTraceMetadata(DeclWithIssue); });
326 CacheInitializer::initialize(DeclWithIssue, SuppressionRanges);
332 return llvm::any_of(SuppressionRanges,
334 return fullyContains(Suppression, BugRange,
SM);
static const T * chooseDefinitionRedecl(const T *Tmpl)
static const ClassTemplateDecl * walkInstantiatedFromChain(const ClassTemplateDecl *Tmpl)
static const Decl * preferTemplateDefinitionForTemplateSpecializations(const Decl *D)
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
SourceManager & getSourceManager()
Attr - This represents one attribute.
Represents an attribute applied to a statement.
ArrayRef< const Attr * > getAttrs() const
Declaration of a class template.
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
bool isMemberSpecialization() const
Determines whether this class template partial specialization template was a specialization of a memb...
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
const char * getDeclKindName() const
SourceLocation getBeginLoc() const LLVM_READONLY
TranslationUnitDecl * getTranslationUnitDecl()
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Represents a function declaration or definition.
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
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.
llvm::ArrayRef< llvm::StringRef > DiagnosticIdentifierList
bool isSuppressed(const BugReport &)
Return true if the given bug report was explicitly suppressed by the user.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
void initialize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)