Author: dergachev Date: Wed Jun 19 16:33:48 2019 New Revision: 363895 URL: http://llvm.org/viewvc/llvm-project?rev=363895&view=rev Log: [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 Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp cfe/trunk/test/Analysis/dump_egraph.cpp cfe/trunk/test/Analysis/expr-inspection.c Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=363895&r1=363894&r2=363895&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original) +++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Wed Jun 19 16:33:48 2019 @@ -527,7 +527,8 @@ void LocationContext::printJson(raw_ostr unsigned Frame = 0; for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) { - Indent(Out, Space, IsDot) << "{ \"location_context\": \""; + Indent(Out, Space, IsDot) + << "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \""; switch (LCtx->getKind()) { case StackFrame: Out << '#' << Frame << " Call\", \"calling\": \""; @@ -541,7 +542,7 @@ void LocationContext::printJson(raw_ostr if (const Stmt *S = cast<StackFrameContext>(LCtx)->getCallSite()) { Out << '\"'; printLocation(Out, SM, S->getBeginLoc()); - Out << '\"'; + Out << '\"'; } else { Out << "null"; } Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=363895&r1=363894&r2=363895&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Wed Jun 19 16:33:48 2019 @@ -261,8 +261,7 @@ void Environment::printJson(raw_ostream const Stmt *S = I->first.getStmt(); Indent(Out, InnerSpace, IsDot) - << "{ \"lctx_id\": " << LC->getID() - << ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": "; + << "{ \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": "; S->printJson(Out, nullptr, PP, /*AddQuotes=*/true); Out << ", \"value\": "; Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=363895&r1=363894&r2=363895&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jun 19 16:33:48 2019 @@ -149,9 +149,6 @@ public: if (!S) I = getItem().getCXXCtorInitializer(); - // IDs - Out << "\"lctx_id\": " << getLocationContext()->getID() << ", "; - if (S) Out << "\"stmt_id\": " << S->getID(getASTContext()); else Modified: cfe/trunk/test/Analysis/dump_egraph.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=363895&r1=363894&r2=363895&view=diff ============================================================================== --- cfe/trunk/test/Analysis/dump_egraph.cpp (original) +++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed Jun 19 16:33:48 2019 @@ -18,9 +18,9 @@ void foo() { new S; } -// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l \{ \"lctx_id\": 1, \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\" +// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l \{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\" -// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l \{ \"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\" +// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l \{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\" // CHECK: \"cluster\": \"t\", \"items\": [\l \{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\" Modified: cfe/trunk/test/Analysis/expr-inspection.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/expr-inspection.c?rev=363895&r1=363894&r2=363895&view=diff ============================================================================== --- cfe/trunk/test/Analysis/expr-inspection.c (original) +++ cfe/trunk/test/Analysis/expr-inspection.c Wed Jun 19 16:33:48 2019 @@ -30,8 +30,8 @@ void foo(int x) { // CHECK-NEXT: ]} // CHECK-NEXT: ], // CHECK-NEXT: "environment": [ -// CHECK-NEXT: { "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [ -// CHECK-NEXT: { "lctx_id": 1, "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" } +// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [ +// CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" } // CHECK-NEXT: ]} // CHECK-NEXT: ], // CHECK-NEXT: "constraints": [ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits