27class NoDeleteChecker :
public Checker<check::ASTDecl<TranslationUnitDecl>> {
29 mutable BugReporter *BR =
nullptr;
30 mutable TrivialFunctionAnalysis TFA;
35 "Incorrect [[clang::annotate_type(\"webkit.nodelete\")]] "
37 "WebKit coding guidelines") {}
39 void checkASTDecl(
const TranslationUnitDecl *TUD, AnalysisManager &MGR,
40 BugReporter &BRArg)
const {
47 const NoDeleteChecker *Checker;
48 Decl *DeclWithIssue{
nullptr};
50 explicit LocalVisitor(
const NoDeleteChecker *Checker) : Checker(Checker) {
52 ShouldVisitTemplateInstantiations =
true;
53 ShouldWalkTypesOfTypeLocs =
true;
54 ShouldVisitImplicitCode =
false;
55 ShouldVisitLambdaBody =
true;
58 bool VisitFunctionDecl(
const FunctionDecl *FD)
override {
59 Checker->visitFunctionDecl(FD);
64 LocalVisitor visitor(
this);
65 visitor.TraverseDecl(
const_cast<TranslationUnitDecl *
>(TUD));
68 static bool hasNoDeleteAnnotation(
const FunctionDecl *FD) {
72 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
73 if (!MD || !MD->isVirtual())
76 auto Overriders = llvm::to_vector(MD->overridden_methods());
77 while (!Overriders.empty()) {
78 const auto *
Fn = Overriders.pop_back_val();
79 llvm::append_range(Overriders,
Fn->overridden_methods());
87 void visitFunctionDecl(
const FunctionDecl *FD)
const {
91 if (!hasNoDeleteAnnotation(FD))
95 if (!Body || TFA.isTrivial(Body))
99 llvm::raw_svector_ostream Os(Buf);
103 Os <<
" has [[clang::annotate_type(\"webkit.nodelete\")]] but it contains "
104 "code that could destruct an object";
106 const SourceLocation SrcLocToReport = FD->
getBeginLoc();
107 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
108 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
110 Report->setDeclWithIssue(FD);
111 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.
SourceLocation getBeginLoc() const LLVM_READONLY
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
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)