22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
43 const CheckerBase *Checker) {
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 '" 60 <<
"'. A method with the same name (same selector) is also defined in " 63 <<
"' and has a return type of '" 65 <<
"'. These two types are incompatible, and may result in undefined " 66 "behavior for clients of these classes.";
68 PathDiagnosticLocation MethDLoc =
70 BR.getSourceManager());
73 MethDerived, Checker,
"Incompatible instance method return type",
80 const CheckerBase *Checker) {
91 typedef llvm::DenseMap<Selector,ObjCMethodDecl*>
MapTy;
93 unsigned NumMethods = 0;
96 IMeths[M->getSelector()] = M;
102 while (C && NumMethods) {
106 MapTy::iterator MI = IMeths.find(S);
108 if (MI == IMeths.end() || MI->second ==
nullptr)
113 MI->second =
nullptr;
127 class ObjCMethSigsChecker :
public Checker<
128 check::ASTDecl<ObjCImplementationDecl> > {
131 BugReporter &BR)
const {
137 void ento::registerObjCMethSigsChecker(CheckerManager &mgr) {
138 mgr.registerChecker<ObjCMethSigsChecker>();
141 bool ento::shouldRegisterObjCMethSigsChecker(
const LangOptions &LO) {
Defines the clang::ASTContext interface.
const char *const CoreFoundationObjectiveC
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
ObjCInterfaceDecl * getClassInterface()
C Language Family Type Representation.
llvm::DenseMap< Stmt *, Stmt * > MapTy
ObjCMethodDecl - Represents an instance or class method declaration.
static bool AreTypesCompatible(QualType Derived, QualType Ancestor, ASTContext &C)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
instmeth_range instance_methods() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static void CheckObjCInstMethSignature(const ObjCImplementationDecl *ID, BugReporter &BR, const CheckerBase *Checker)
Represents an ObjC class declaration.
QualType getReturnType() const
static void CompareReturnTypes(const ObjCMethodDecl *MethDerived, const ObjCMethodDecl *MethAncestor, BugReporter &BR, ASTContext &Ctx, const ObjCImplementationDecl *ID, const CheckerBase *Checker)
ObjCInterfaceDecl * getSuperClass() const
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
Selector getSelector() const
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
bool isAnyPointerType() const
const ObjCInterfaceDecl * getClassInterface() const
Dataflow Directional Tag Classes.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.