[clang] [clang] [diagnostics] Add `-fdiagnostics-add-output` switch for SARIF (PR #185201)

Dave Bartolomeo via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 10:01:56 PDT 2026


================
@@ -342,9 +342,9 @@ SarifDocumentWriter::createCodeFlow(ArrayRef<ThreadFlow> ThreadFlows) {
   return json::Object{{"threadFlows", createThreadFlows(ThreadFlows)}};
 }
 
-void SarifDocumentWriter::createRun(StringRef ShortToolName,
-                                    StringRef LongToolName,
-                                    StringRef ToolVersion) {
+void SarifDocumentWriter::createRun(std::string ShortToolName,
+                                    std::string LongToolName,
+                                    std::string ToolVersion) {
----------------
dbartol wrote:

The original bug was because `json::Value` (used in the initializer list to `json::Object`) has a constructor overload for `StringRef` that captures the string by reference. I can see why that functionality is useful, but it's easy to get the lifetimes wrong when that behavior is implicit. I thought it was more clear to make `createRun` take owning strings than it was to make sure that wherever I used the `StringRef` arguments I remembered to convert them to `std::string`.


https://github.com/llvm/llvm-project/pull/185201


More information about the cfe-commits mailing list