20 #include "llvm/Support/Debug.h" 22 using namespace clang;
28 const char *WarnAtNode =
"OSObjCast";
30 class OSObjectCStyleCastChecker :
public Checker<check::ASTCodeBody> {
32 void checkASTCodeBody(
const Decl *D,
34 BugReporter &BR)
const;
40 const OSObjectCStyleCastChecker *Checker) {
44 std::string Diagnostics;
45 llvm::raw_string_ostream
OS(Diagnostics);
46 OS <<
"C-style cast of OSObject. Use OSDynamicCast instead.";
51 "OSObject C-Style Cast",
55 CE->getSourceRange());
63 void OSObjectCStyleCastChecker::checkASTCodeBody(
const Decl *D, AnalysisManager &AM,
64 BugReporter &BR)
const {
70 auto OSObjTypeM = hasTypePointingTo(
cxxRecordDecl(isDerivedFrom(
"OSMetaClassBase")));
71 auto OSObjSubclassM = hasTypePointingTo(
76 OSObjSubclassM)).bind(WarnAtNode);
84 void ento::registerOSObjectCStyleCast(CheckerManager &Mgr) {
85 Mgr.registerChecker<OSObjectCStyleCastChecker>();
88 bool ento::shouldRegisterOSObjectCStyleCast(
const LangOptions &LO) {
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher< Decl >, void(internal::HasDeclarationSupportedTypes)> hasDeclaration(const internal::Matcher< Decl > &InnerMatcher)
Matches a node if the declaration associated with that node matches the given matcher.
Decl - This represents one declaration (or definition), e.g.
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> allOf
Matches if all given matchers match.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
BoundNodesTreeBuilder Nodes
AnalysisDeclContext contains the context data for the function or method under analysis.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const T * getNodeAs(StringRef ID) const
Returns the AST node bound to ID.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachDescendantMatcher > forEachDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher. ...
const internal::VariadicDynCastAllOfMatcher< Stmt, CStyleCastExpr > cStyleCastExpr
Matches a C-style cast expression.
Maps string IDs to AST nodes matched by parts of a matcher.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
const Decl * getDecl() const
static void emitDiagnostics(BoundNodes &Match, const Decl *D, BugReporter &BR, AnalysisManager &AM, const ObjCAutoreleaseWriteChecker *Checker)
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
Dataflow Directional Tag Classes.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl > cxxRecordDecl
Matches C++ class declarations.
Indicates that the tracking object is a descendant of a referenced-counted OSObject, used in the Darwin kernel.
internal::Matcher< NamedDecl > hasName(const std::string &Name)
Matches NamedDecl nodes that have the specified name.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.