Skip to content

Commit f9f6cdb

Browse files
committed
[analyzer] Fix JSON dumps for location contexts.
Location context ID is a property of the location context, not of an item within it. It's useful to know the id even when there are no items in the context, eg. for the purposes of figuring out how did contents of the Environment for the same location context changed across states. Differential Revision: https://reviews.llvm.org/D62754 llvm-svn: 363895
1 parent 3bb7b2e commit f9f6cdb

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

clang/lib/Analysis/AnalysisDeclContext.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ void LocationContext::printJson(raw_ostream &Out, const char *NL,
527527

528528
unsigned Frame = 0;
529529
for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
530-
Indent(Out, Space, IsDot) << "{ \"location_context\": \"";
530+
Indent(Out, Space, IsDot)
531+
<< "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
531532
switch (LCtx->getKind()) {
532533
case StackFrame:
533534
Out << '#' << Frame << " Call\", \"calling\": \"";
@@ -541,7 +542,7 @@ void LocationContext::printJson(raw_ostream &Out, const char *NL,
541542
if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) {
542543
Out << '\"';
543544
printLocation(Out, SM, S->getBeginLoc());
544-
Out << '\"';
545+
Out << '\"';
545546
} else {
546547
Out << "null";
547548
}

clang/lib/StaticAnalyzer/Core/Environment.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
261261

262262
const Stmt *S = I->first.getStmt();
263263
Indent(Out, InnerSpace, IsDot)
264-
<< "{ \"lctx_id\": " << LC->getID()
265-
<< ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
264+
<< "{ \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
266265
S->printJson(Out, nullptr, PP, /*AddQuotes=*/true);
267266

268267
Out << ", \"value\": ";

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ class ConstructedObjectKey {
149149
if (!S)
150150
I = getItem().getCXXCtorInitializer();
151151

152-
// IDs
153-
Out << "\"lctx_id\": " << getLocationContext()->getID() << ", ";
154-
155152
if (S)
156153
Out << "\"stmt_id\": " << S->getID(getASTContext());
157154
else

clang/test/Analysis/dump_egraph.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ void foo() {
1818
new S;
1919
}
2020

21-
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 1, \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\"
21+
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\"
2222

23-
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\"
23+
// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\"
2424

2525
// CHECK: \"cluster\": \"t\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
2626

clang/test/Analysis/expr-inspection.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void foo(int x) {
3030
// CHECK-NEXT: ]}
3131
// CHECK-NEXT: ],
3232
// CHECK-NEXT: "environment": [
33-
// CHECK-NEXT: { "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
34-
// CHECK-NEXT: { "lctx_id": 1, "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
33+
// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
34+
// CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
3535
// CHECK-NEXT: ]}
3636
// CHECK-NEXT: ],
3737
// CHECK-NEXT: "constraints": [

0 commit comments

Comments
 (0)