28class NoDeleteChecker :
public Checker<check::ASTDecl<TranslationUnitDecl>> {
30 mutable BugReporter *BR =
nullptr;
31 mutable TrivialFunctionAnalysis TFA;
36 "Incorrect [[clang::annotate_type(\"webkit.nodelete\")]] "
38 "WebKit coding guidelines") {}
40 void checkASTDecl(
const TranslationUnitDecl *TUD, AnalysisManager &MGR,
41 BugReporter &BRArg)
const {
48 const NoDeleteChecker *Checker;
49 Decl *DeclWithIssue{
nullptr};
51 explicit LocalVisitor(
const NoDeleteChecker *Checker) : Checker(Checker) {
53 ShouldVisitTemplateInstantiations =
true;
54 ShouldWalkTypesOfTypeLocs =
true;
55 ShouldVisitImplicitCode =
false;
56 ShouldVisitLambdaBody =
true;
59 bool VisitFunctionDecl(
const FunctionDecl *FD)
override {
60 Checker->visitFunctionDecl(FD);
65 LocalVisitor visitor(
this);
66 visitor.TraverseDecl(
const_cast<TranslationUnitDecl *
>(TUD));
69 void visitFunctionDecl(
const FunctionDecl *FD)
const {
80 NamedDecl *ParamDecl =
nullptr;
82 if (!TFA.hasTrivialDtor(D)) {
87 const Stmt *OffendingStmt =
nullptr;
88 if (!ParamDecl && TFA.isTrivial(Body, &OffendingStmt))
92 llvm::raw_svector_ostream Os(Buf);
96 Os <<
" has [[clang::annotate_type(\"webkit.nodelete\")]] but it contains ";
97 SourceLocation SrcLocToReport;
100 Os <<
"a parameter ";
102 Os <<
" which could destruct an object.";
106 Os <<
"code that could destruct an object.";
111 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
112 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
114 Report->setDeclWithIssue(FD);
115 BR->emitReport(std::move(
Report));
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::SourceLocation class and associated facilities.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
SourceLocation getBeginLoc() const LLVM_READONLY
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
ArrayRef< ParmVarDecl * > parameters() const
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
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.
void printQuotedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
bool isNoDeleteFunction(const FunctionDecl *F)