20#include "llvm/Support/Casting.h"
28class NoUncountedMemberChecker
29 :
public Checker<check::ASTDecl<TranslationUnitDecl>> {
35 NoUncountedMemberChecker()
37 "Member variable is a raw-pointer/reference to reference-countable "
39 "WebKit coding guidelines") {}
49 const NoUncountedMemberChecker *
Checker;
50 explicit LocalVisitor(
const NoUncountedMemberChecker *
Checker)
55 bool shouldVisitTemplateInstantiations()
const {
return true; }
56 bool shouldVisitImplicitCode()
const {
return false; }
64 LocalVisitor visitor(
this);
68 void visitRecordDecl(
const RecordDecl *RD)
const {
69 if (shouldSkipDecl(RD))
73 const Type *MemberType =
Member->getType().getTypePtrOrNull();
79 if (MemberCXXRD->hasDefinition()) {
81 if (isRCAble && *isRCAble)
82 reportBug(
Member, MemberType, MemberCXXRD, RD);
88 bool shouldSkipDecl(
const RecordDecl *RD)
const {
101 if (!RDLocation.isValid())
106 if (Kind != TagTypeKind::Struct && Kind != TagTypeKind::Class)
115 auto CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(RD);
130 llvm::raw_svector_ostream Os(Buf);
132 Os <<
"Member variable ";
137 << (isa<PointerType>(MemberType) ?
"raw pointer" :
"reference")
138 <<
" to ref-countable type ";
140 Os <<
"; member variables must be ref-counted.";
144 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
145 Report->addRange(
Member->getSourceRange());
155bool ento::shouldRegisterNoUncountedMemberChecker(
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Represents a C++ struct/union/class.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getLocation() const
Represents a member of a struct/union/class.
Represents a struct/union/class.
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
TagKind getTagKind() const
The top declaration context.
The base class of the type hierarchy.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
BugReporter is a utility class for generating PathDiagnostics for analysis.
const SourceManager & getSourceManager()
virtual void emitReport(std::unique_ptr< BugReport > R)
Add the given report to the set of reports tracked by BugReporter.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
The JSON file list parser is used to communicate input to InstallAPI.
void printQuotedQualifiedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
void printQuotedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
std::optional< bool > isRefCountable(const CXXRecordDecl *R)
bool isRefCounted(const CXXRecordDecl *R)