[clang] [Clang][Diagnose] New feature: Nested/Indented diagnostic message in sarif mode. (PR #174106)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 1 00:46:31 PST 2026


================
@@ -55,28 +59,64 @@ class SARIFDiagnostic : public DiagnosticRenderer {
                                   StringRef ModuleName) override;
 
 private:
-  // Shared between SARIFDiagnosticPrinter and this renderer.
-  SarifDocumentWriter *Writer;
-
-  SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
-                                  PresumedLoc PLoc,
-                                  ArrayRef<CharSourceRange> Ranges,
-                                  const Diagnostic &Diag);
-
-  SarifResult addRelatedLocationToResult(SarifResult Result, FullSourceLoc Loc,
-                                         PresumedLoc PLoc);
-
-  llvm::SmallVector<CharSourceRange>
-  getSarifLocation(FullSourceLoc Loc, PresumedLoc PLoc,
-                   ArrayRef<CharSourceRange> Ranges);
-
-  SarifRule addDiagnosticLevelToRule(SarifRule Rule,
-                                     DiagnosticsEngine::Level Level);
-
-  llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
-
-  llvm::SmallVector<std::pair<FullSourceLoc, PresumedLoc>>
-      RelatedLocationsCache;
+  class Node {
+  public:
+    // Subclasses
+    struct Result {
+      DiagnosticsEngine::Level Level;
+      std::string Message;
+      DiagOrStoredDiag Diag;
----------------
anonymouspc wrote:

I agree with you. this `Message` seems to be redundant. But the interface of `DiagnosticRenderer` is
```cpp
// clang/Frontend/DiagnosticRenderer.h:75
virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
                                     DiagnosticsEngine::Level Level,
                                     StringRef Message,
                                     ArrayRef<CharSourceRange> Ranges,
                                     DiagOrStoredDiag Info) = 0;
```
I also don't know what's the differences between a `Message` and a `StoredDiagnostic.getMessage()`. But we just "forwards" and copy them here.

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


More information about the cfe-commits mailing list