clang: lib/Analysis/ProgramPoint.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

18

19using namespace clang;

20

22

26 switch (K) {

27 default:

28 llvm_unreachable("Unhandled ProgramPoint kind");

30 return PreStmt(S, LC, tag);

34 return PreLoad(S, LC, tag);

45 }

46}

47

50}

51

57 const bool AddQuotes = true;

58

59 Out << "\"kind\": \"";

62 Out << "BlockEntrance\""

63 << ", \"block_id\": "

64 << castAs().getBlock()->getBlockID();

65 break;

66

68 auto FEP = getAs();

69 Out << "FunctionExit\""

70 << ", \"block_id\": " << FEP->getBlock()->getBlockID()

71 << ", \"stmt_id\": ";

72

73 if (const ReturnStmt *RS = FEP->getStmt()) {

74 Out << RS->getID(Context) << ", \"stmt\": ";

75 RS->printJson(Out, nullptr, PP, AddQuotes);

76 } else {

77 Out << "null, \"stmt\": null";

78 }

79 break;

80 }

82 llvm_unreachable("BlockExitKind");

83 break;

85 Out << "CallEnter\", \"callee_decl\": \"";

87 castAs().getCalleeContext()->getDecl())

88 << '\"';

89 break;

91 Out << "CallExitBegin\"";

92 break;

94 Out << "CallExitEnd\"";

95 break;

97 Out << "EpsilonPoint\"";

98 break;

99

101 Out << "LoopExit\", \"stmt\": \""

102 << castAs().getLoopStmt()->getStmtClassName() << '\"';

103 break;

104

107 Out << "PreCall\", \"decl\": \""

109 << "\", \"location\": ";

111 break;

112 }

113

116 Out << "PostCall\", \"decl\": \""

118 << "\", \"location\": ";

120 break;

121 }

122

124 Out << "PostInitializer\", ";

126 if (const FieldDecl *FD = Init->getAnyMember()) {

127 Out << "\"field_decl\": \"" << *FD << '\"';

128 } else {

129 Out << "\"type\": \"";

130 QualType Ty = Init->getTypeSourceInfo()->getType();

133 Out << '\"';

134 }

135 break;

136 }

137

139 const BlockEdge &E = castAs();

140 const Stmt *T = E.getSrc()->getTerminatorStmt();

141 Out << "Edge\", \"src_id\": " << E.getSrc()->getBlockID()

142 << ", \"dst_id\": " << E.getDst()->getBlockID() << ", \"terminator\": ";

143

144 if (T) {

145 Out << "null, \"term_kind\": null";

146 break;

147 }

148

149 E.getSrc()->printTerminatorJson(Out, Context.getLangOpts(),

150 true);

151 Out << ", \"location\": ";

153

154 Out << ", \"term_kind\": \"";

155 if (isa(T)) {

156 Out << "SwitchStmt\", \"case\": ";

157 if (const Stmt *Label = E.getDst()->getLabel()) {

158 if (const auto *C = dyn_cast(Label)) {

159 Out << "{ \"lhs\": ";

160 if (const Stmt *LHS = C->getLHS()) {

161 LHS->printJson(Out, nullptr, PP, AddQuotes);

162 } else {

163 Out << "null";

164 }

165

166 Out << ", \"rhs\": ";

167 if (const Stmt *RHS = C->getRHS()) {

168 RHS->printJson(Out, nullptr, PP, AddQuotes);

169 } else {

170 Out << "null";

171 }

172 Out << " }";

173 } else {

174 assert(isa(Label));

175 Out << "\"default\"";

176 }

177 } else {

178 Out << "\"implicit default\"";

179 }

180 } else if (isa(T)) {

181

182 Out << "IndirectGotoStmt\"";

183 } else {

184 Out << "Condition\", \"value\": "

185 << (*E.getSrc()->succ_begin() == E.getDst() ? "true" : "false");

186 }

187 break;

188 }

189

190 default: {

191 const Stmt *S = castAs().getStmt();

192 assert(S != nullptr && "Expecting non-null Stmt");

193

194 Out << "Statement\", \"stmt_kind\": \"" << S->getStmtClassName()

195 << "\", \"stmt_id\": " << S->getID(Context)

196 << ", \"pointer\": \"" << (const void *)S << "\", ";

197 if (const auto *CS = dyn_cast(S))

198 Out << "\"cast_kind\": \"" << CS->getCastKindName() << "\", ";

199

200 Out << "\"pretty\": ";

201

202 S->printJson(Out, nullptr, PP, AddQuotes);

203

204 Out << ", \"location\": ";

206

207 Out << ", \"stmt_point_kind\": \"";

208 if (getAs())

209 Out << "PreLoad";

210 else if (getAs())

211 Out << "PreStore";

212 else if (getAs())

213 Out << "PostAllocatorCall";

214 else if (getAs())

215 Out << "PostCondition";

216 else if (getAs())

217 Out << "PostLoad";

218 else if (getAs())

219 Out << "PostLValue";

220 else if (getAs())

221 Out << "PostStore";

222 else if (getAs())

223 Out << "PostStmt";

224 else if (getAs())

225 Out << "PostStmtPurgeDeadSymbols";

226 else if (getAs())

227 Out << "PreStmtPurgeDeadSymbols";

228 else if (getAs())

229 Out << "PreStmt";

230 else {

231 Out << "\nKind: '" << getKind();

232 llvm_unreachable("' is unhandled StmtPoint kind!");

233 }

234

235 Out << '\"';

236 break;

237 }

238 }

239}

240

242 StringRef Msg)

243 : Desc((MsgProvider + " : " + Msg).str()) {}

244

246 return Desc;

247}

Defines the clang::ASTContext interface.

This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

SourceManager & getSourceManager()

const LangOptions & getLangOpts() const

const clang::PrintingPolicy & getPrintingPolicy() const

static std::string getFunctionName(const Decl *D)

ASTContext & getASTContext() const

Represents a C++ base or member initializer.

FunctionDecl * getAsFunction() LLVM_READONLY

Returns the function itself, or the templated function if this is a function template.

Represents a member of a struct/union/class.

Represents an implicit call event.

SourceLocation getLocation() const

const Decl * getDecl() const

It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...

LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const

std::string getQualifiedNameAsString() const

Represents a point after we ran remove dead bindings AFTER processing the given statement.

Represents a point after we ran remove dead bindings BEFORE processing the given statement.

ProgramPoints can be "tagged" as representing points specific to a given analysis entity.

virtual ~ProgramPointTag()

static ProgramPoint getProgramPoint(const Stmt *S, ProgramPoint::Kind K, const LocationContext *LC, const ProgramPointTag *tag)

LLVM_DUMP_METHOD void dump() const

void printJson(llvm::raw_ostream &Out, const char *NL="\n") const

@ PreStmtPurgeDeadSymbolsKind

@ PostStmtPurgeDeadSymbolsKind

const LocationContext * getLocationContext() const

A (possibly-)qualified type.

QualType getLocalUnqualifiedType() const

Return this type with all of the instance-specific qualifiers removed, but without removing any quali...

void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const

ReturnStmt - This represents a return, optionally of an expression: return; return 4;.

SimpleProgramPointTag(StringRef MsgProvider, StringRef Msg)

StringRef getTagDescription() const override

This class handles loading and caching of source files into memory.

Stmt - This represents one statement.

The JSON file list parser is used to communicate input to InstallAPI.

void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc, const SourceManager &SM, bool AddBraces=true)

const FunctionProtoType * T

Describes how types, statements, expressions, and declarations should be printed.