clang: include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H

25#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H

26

27#include

28

36#include "llvm/ADT/STLFunctionalExtras.h"

37

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

65

66

67

68

69

70

71

72

73

74

75

76const FunctionDecl *

78

79

80

81

82

83

84

85

86template

88 const CallExpr *DerefExpr, RecordStorageLocation *SmartPointerLoc,

89 TransferState &State,

90 llvm::function_ref<void(StorageLocation &)> InitializeLoc);

91

92

93

94

95

96

97

98template

100 const CallExpr *GetExpr, RecordStorageLocation *SmartPointerLoc,

101 TransferState &State,

102 llvm::function_ref<void(StorageLocation &)> InitializeLoc);

103

104template

108 llvm::function_ref<void(StorageLocation &)> InitializeLoc) {

109 if (State.Env.getStorageLocation(*DerefExpr) != nullptr)

110 return;

111 if (SmartPointerLoc == nullptr)

112 return;

113

115 if (Callee == nullptr)

116 return;

119

120 assert(CanonicalCallee != nullptr);

121 if (CanonicalCallee != Callee) {

122

123

125 Callee->getReturnType()->isReferenceType());

129 Callee->getReturnType()

130 .getNonReferenceType()

131 ->getCanonicalTypeUnqualified());

132 }

133

135 State.Lattice.getOrCreateConstMethodReturnStorageLocation(

136 *SmartPointerLoc, CanonicalCallee, State.Env, InitializeLoc);

137 State.Env.setStorageLocation(*DerefExpr, LocForValue);

138}

139

140template

144 llvm::function_ref<void(StorageLocation &)> InitializeLoc) {

145 if (SmartPointerLoc == nullptr)

146 return;

147

150

151 if (CanonicalCallee != nullptr) {

152 auto &LocForValue =

153 State.Lattice.getOrCreateConstMethodReturnStorageLocation(

154 *SmartPointerLoc, CanonicalCallee, State.Env, InitializeLoc);

155 State.Env.setValue(*GetExpr,

156 State.Env.template create(LocForValue));

157 } else {

158

159 Value *Val = State.Lattice.getOrCreateConstMethodReturnValue(

160 *SmartPointerLoc, GetExpr, State.Env);

161 if (Val == nullptr)

162 return;

163 State.Env.setValue(*GetExpr, *Val);

164 }

165}

166

167}

168

169#endif

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

FunctionDecl * getDirectCallee()

If the callee is a FunctionDecl, return it. Otherwise return null.

Represents a function declaration or definition.

QualType getReturnType() const

QualType getNonReferenceType() const

If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...

CanQualType getCanonicalTypeUnqualified() const

bool isReferenceType() const

A storage location for a record (struct, class, or union).

Base class for elements of the local variable store and of the heap.

Base class for all values computed by abstract interpretation.

internal::Matcher< Stmt > StatementMatcher

Dataflow Directional Tag Classes.

void transferSmartPointerLikeCachedDeref(const CallExpr *DerefExpr, RecordStorageLocation *SmartPointerLoc, TransferState< LatticeT > &State, llvm::function_ref< void(StorageLocation &)> InitializeLoc)

A transfer function for operator* (and value) calls that can be cached.

void transferSmartPointerLikeCachedGet(const CallExpr *GetExpr, RecordStorageLocation *SmartPointerLoc, TransferState< LatticeT > &State, llvm::function_ref< void(StorageLocation &)> InitializeLoc)

A transfer function for operator-> (and get) calls that can be cached.

ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall()

ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall()

ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow()

const FunctionDecl * getCanonicalSmartPointerLikeOperatorCallee(const CallExpr *CE)

Returns the "canonical" callee for smart pointer operators (* and ->) as a key for caching.

ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar()

Matchers: For now, these match on any class with an operator* or operator-> where the return types ha...

A common form of state shared between the cases of a transfer function.