23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/Support/raw_ostream.h" 26 using namespace clang;
51 llvm::raw_string_ostream os(sbuf);
53 os <<
"The Objective-C class '" 55 <<
"', which is derived from class '" 57 <<
"', defines the instance method '";
59 os <<
"' whose return type is '" 61 <<
"'. A method with the same name (same selector) is also defined in " 64 <<
"' and has a return type of '" 66 <<
"'. These two types are incompatible, and may result in undefined " 67 "behavior for clients of these classes.";
74 MethDerived, Checker,
"Incompatible instance method return type",
92 typedef llvm::DenseMap<Selector,ObjCMethodDecl*>
MapTy;
94 unsigned NumMethods = 0;
97 IMeths[M->getSelector()] = M;
103 while (C && NumMethods) {
107 MapTy::iterator MI = IMeths.find(S);
109 if (MI == IMeths.end() || MI->second ==
nullptr)
114 MI->second =
nullptr;
128 class ObjCMethSigsChecker :
public Checker<
129 check::ASTDecl<ObjCImplementationDecl> > {
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
ASTContext & getContext()
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
BugReporter is a utility class for generating PathDiagnostics for analysis.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
CHECKER * registerChecker()
Used to register checkers.
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
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...
SourceManager & getSourceManager()
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.