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 void visitFunctionDecl(
const FunctionDecl *FD)
const {
73 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
74 if (
auto *Cls = MD->getParent(); Cls && MD->isVirtual()) {
79 [&](
const CXXBaseSpecifier *Base, CXXBasePath &) {
80 const Type *
T =
Base->getType().getTypePtrOrNull();
88 for (
const CXXMethodDecl *BaseMD : R->
methods()) {
89 if (BaseMD->getCorrespondingMethodInClass(Cls) == MD) {
91 HasNoDeleteAnnotation =
true;
103 if (!Body || TFA.isTrivial(Body))
106 SmallString<100> Buf;
107 llvm::raw_svector_ostream Os(Buf);
111 Os <<
" has [[clang::annotate_type(\"webkit.nodelete\")]] but it contains "
112 "code that could destruct an object";
114 const SourceLocation SrcLocToReport = FD->
getBeginLoc();
115 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
116 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
118 Report->setDeclWithIssue(FD);
119 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.
void setOrigin(const CXXRecordDecl *Rec)
method_range methods() const
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.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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
const FunctionProtoType * T
@ Type
The name was classified as a type.
bool isNoDeleteFunction(const FunctionDecl *F)