diff options
-rw-r--r-- | llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageExporterJson.cpp | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp index f754052412e..799f56bed42 100644 --- a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp +++ b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -70,4 +70,6 @@ int main() { // TEXT: 161| [[@LINE]]|int main( // HTML-WHOLE-FILE: <td class='uncovered-line'></td><td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='code'><pre>// after // HTML-FILTER-NOT: <td class='uncovered-line'></td><td class='line-number'><a name='L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='code'><pre>// after -// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null | FileCheck %S/Inputs/lineExecutionCounts.json +// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null > %t.export.json +// RUN: FileCheck -input-file %t.export.json %S/Inputs/lineExecutionCounts.json +// RUN: cat %t.export.json | %python -c "import json, sys; json.loads(sys.stdin.read())" diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp index 4ce07b59f0f..7941f288597 100644 --- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp +++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp @@ -86,7 +86,16 @@ class CoverageExporterJson { void emitSerialized(const int64_t Value) { OS << Value; } /// \brief Emit a serialized string. - void emitSerialized(const std::string &Value) { OS << "\"" << Value << "\""; } + void emitSerialized(const std::string &Value) { + OS << "\""; + for (char C : Value) { + if (C != '\\') + OS << C; + else + OS << "\\\\"; + } + OS << "\""; + } /// \brief Emit a comma if there is a previous element to delimit. void emitComma() { @@ -109,7 +118,8 @@ class CoverageExporterJson { /// \brief Emit a dictionary/object key but no value. void emitDictKey(const std::string &Key) { emitComma(); - OS << "\"" << Key << "\":"; + emitSerialized(Key); + OS << ":"; State.pop(); assert((State.size() >= 1) && "Closed too many JSON elements"); |