22#include "llvm/ADT/DenseMap.h"
23#include "llvm/Support/raw_ostream.h"
36 return C.typesAreCompatible(Derived, Ancestor);
50 llvm::raw_string_ostream os(sbuf);
52 os <<
"The Objective-C class '"
54 <<
"', which is derived from class '"
56 <<
"', defines the instance method '";
58 os <<
"' whose return type is '" << ResDerived
59 <<
"'. A method with the same name (same selector) is also defined in "
63 <<
"'. These two types are incompatible, and may result in undefined "
64 "behavior for clients of these classes.";
71 MethDerived,
Checker,
"Incompatible instance method return type",
89 typedef llvm::DenseMap<Selector,ObjCMethodDecl*>
MapTy;
91 unsigned NumMethods = 0;
93 for (
auto *M : ID->instance_methods()) {
94 IMeths[M->getSelector()] = M;
100 while (
C && NumMethods) {
101 for (
const auto *M :
C->instance_methods()) {
104 MapTy::iterator MI = IMeths.find(S);
106 if (MI == IMeths.end() || MI->second ==
nullptr)
111 MI->second =
nullptr;
116 C =
C->getSuperClass();
125class ObjCMethSigsChecker :
public Checker<
126 check::ASTDecl<ObjCImplementationDecl> > {
139bool ento::shouldRegisterObjCMethSigsChecker(
const CheckerManager &mgr) {
Defines the clang::ASTContext interface.
static bool AreTypesCompatible(QualType Derived, QualType Ancestor, ASTContext &C)
static void CheckObjCInstMethSignature(const ObjCImplementationDecl *ID, BugReporter &BR, const CheckerBase *Checker)
static void CompareReturnTypes(const ObjCMethodDecl *MethDerived, const ObjCMethodDecl *MethAncestor, BugReporter &BR, ASTContext &Ctx, const ObjCImplementationDecl *ID, const CheckerBase *Checker)
llvm::DenseMap< Stmt *, Stmt * > MapTy
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
Selector getSelector() const
QualType getReturnType() const
ObjCInterfaceDecl * getClassInterface()
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
bool isAnyPointerType() const
BugReporter is a utility class for generating PathDiagnostics for analysis.
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=std::nullopt, ArrayRef< FixItHint > Fixits=std::nullopt)
ASTContext & getContext()
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
const char *const CoreFoundationObjectiveC
The JSON file list parser is used to communicate input to InstallAPI.