[PATCH] D129538: [clang] adds prototype for being able to alternate diagnostic formats

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 11 22:00:12 PDT 2022


cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In an effort to move from unstructured text diagnostics to structured
diagnostics, while keeping support for the existing model, we need to
introduce a way to hotswap between the desired modes. The visitor
pattern is a natural ally here because it allows us to defer logic to
handlers that know the specifics of the diagnostic without cluttering
the compiler's logic.

There are two parts to the design: `BasicDiagnostic`, which is used as
an abstract base for errors, warnings, and remarks; and
`DiagnosticContext`, which is used as an abstract base for notes. We've
split diagnostics into these two categories so that it's possible for to
enrich diagnostics with multiple unrelated contexts (notes seem to trail
diagnostics in a detatched and unherded fashion). FixIts are a form of
diagnostic context.

Although parts of `BasicDiagnostic` and `DiagnosticContext` should be
generated via TableGen, we're initially implementing everything manually
so that we can prototype what is necessary: it will be far easier to do
this with a handful of diagnostics than to also figure out how to
integrate this into TableGen at the same time.

**Reviewers should note that testing is currently lacking. Tests for the
diagnostic framework seem to be nonexistent; this should probably
change.**

Depends on: D109701 <https://reviews.llvm.org/D109701>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129538

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/include/clang/Sema/Sema.h
  clang/unittests/Basic/SarifTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129538.443831.patch
Type: text/x-patch
Size: 5647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220712/2377b804/attachment-0001.bin>


More information about the cfe-commits mailing list