clang: lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

22#include "llvm/ADT/DenseMap.h"

23#include "llvm/Support/raw_ostream.h"

24

25using namespace clang;

26using namespace ento;

27

30

31

32

34 return true;

35

36 return C.typesAreCompatible(Derived, Ancestor);

37}

38

44

47

49 std::string sbuf;

50 llvm::raw_string_ostream os(sbuf);

51

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 "

60 "class '"

61 << *MethAncestor->getClassInterface() << "' and has a return type of '"

62 << ResAncestor

63 << "'. These two types are incompatible, and may result in undefined "

64 "behavior for clients of these classes.";

65

69

71 MethDerived, Checker, "Incompatible instance method return type",

73 }

74}

75

79

82

83 if (C)

84 return;

85

87

88

89 typedef llvm::DenseMap<Selector,ObjCMethodDecl*> MapTy;

91 unsigned NumMethods = 0;

92

93 for (auto *M : ID->instance_methods()) {

94 IMeths[M->getSelector()] = M;

95 ++NumMethods;

96 }

97

98

99

100 while (C && NumMethods) {

101 for (const auto *M : C->instance_methods()) {

102 Selector S = M->getSelector();

103

104 MapTy::iterator MI = IMeths.find(S);

105

106 if (MI == IMeths.end() || MI->second == nullptr)

107 continue;

108

109 --NumMethods;

111 MI->second = nullptr;

112

114 }

115

116 C = C->getSuperClass();

117 }

118}

119

120

121

122

123

124namespace {

125class ObjCMethSigsChecker : public Checker<

126 check::ASTDecl > {

127public:

131 }

132};

133}

134

135void ento::registerObjCMethSigsChecker(CheckerManager &mgr) {

137}

138

139bool ento::shouldRegisterObjCMethSigsChecker(const CheckerManager &mgr) {

140 return true;

141}

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()

ASTContext & getContext()

void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges={}, ArrayRef< FixItHint > Fixits={})

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.