[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 08:03:38 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;
----------------
Sirraide wrote:
Ugh, yeah, this API is a bit of a mess: `StoredDiagnostic` has a message and `Diagnostic` may or may not have one, so we just pass it in here. Honestly, `DiagOrStoredDiag` is a bit of an abomination of a type in the first place, so I’d love it if we could just get rid of it entirely and replace all of its uses with `StoredDiagnostic`, and that would allow us to get rid of the `Message` (and some of the other arguments).
That said, I haven’t looked at this in a few months, so I’m not sure if there’s anything that would prevent that; also, such a refactor should be a separate NFC patch.
https://github.com/llvm/llvm-project/pull/174106
More information about the cfe-commits
mailing list