https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/187454
>From 814e14cf81dbcf8d4788c7d0665d06926cf61148 Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Thu, 19 Mar 2026 16:00:10 +0800 Subject: [PATCH 1/2] ~ --- .../infrastructure/clang-tidy-store-check-profile-one-tu.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-store-check-profile-one-tu.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-store-check-profile-one-tu.cpp index 192fbf546d203..9800881af9292 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-store-check-profile-one-tu.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/clang-tidy-store-check-profile-one-tu.cpp @@ -1,9 +1,11 @@ // RUN: rm -rf %t.dir/out // RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%t.dir/out %s -- 2>&1 | not FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-CONSOLE %s // RUN: cat %t.dir/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s +// RUN: cat %t.dir/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | %python -c "import sys, json; json.load(sys.stdin)" // RUN: rm -rf %t.dir/out // RUN: clang-tidy -enable-check-profile -checks='-*,readability-function-size' -store-check-profile=%t.dir/out %s -- 2>&1 // RUN: cat %t.dir/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | FileCheck --match-full-lines -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK-FILE %s +// RUN: cat %t.dir/out/*-clang-tidy-store-check-profile-one-tu.cpp.json | %python -c "import sys, json; json.load(sys.stdin)" // CHECK-CONSOLE-NOT: ===-------------------------------------------------------------------------=== // CHECK-CONSOLE-NOT: {{.*}} --- Name --- >From 49571fc2ae37ec6798f993d37b3ff7cf13de732d Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Thu, 19 Mar 2026 16:23:22 +0800 Subject: [PATCH 2/2] OK, add fix --- .../clang-tidy/ClangTidyProfiling.cpp | 24 +++++++++++++------ clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp index 68b8ae0797acc..1e69d28afea54 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp @@ -45,13 +45,23 @@ void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS, void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS, llvm::TimerGroup &TG) { assert(Storage && "We should have a filename."); - OS << "{\n"; - OS << R"("file": ")" << Storage->SourceFilename << "\",\n"; - OS << R"("timestamp": ")" << Storage->Timestamp << "\",\n"; - OS << "\"profile\": {\n"; - TG.printJSONValues(OS, ""); - OS << "\n}\n"; - OS << "}\n"; + std::string TimestampStr; + llvm::raw_string_ostream TmpOS(TimestampStr); + TmpOS << Storage->Timestamp; + + llvm::json::OStream JOS(OS, 2); + JOS.object([&] { + JOS.attribute("file", Storage->SourceFilename); + JOS.attribute("timestamp", TimestampStr); + JOS.attributeBegin("profile"); + JOS.rawValue([&](llvm::raw_ostream &ROS) { + ROS << "{\n"; + TG.printJSONValues(ROS, ""); + ROS << "\n}"; + }); + JOS.attributeEnd(); + }); + OS << "\n"; OS.flush(); } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 077335c16c331..eafa5883c099e 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -102,6 +102,9 @@ Improvements to clang-tidy manages the creation of temporary header files and ensures that diagnostics and fixes are verified for the specified headers. +- Improved :program:`clang-tidy` ``-store-check-profile`` by generating valid + JSON when the source file path contains characters that require JSON escaping. + New checks ^^^^^^^^^^ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
