[clang] [llvm] DiagnosticHandler: refactor error checking (PR #75889)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 19 13:52:33 PST 2023


================
@@ -256,10 +256,13 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
       RS->emit(*OptDiagBase);
 
   // If there is a report handler, use it.
-  if (pImpl->DiagHandler &&
-      (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
-      pImpl->DiagHandler->handleDiagnostics(DI))
-    return;
+  if (pImpl->DiagHandler) {
+    if (DI.getSeverity() == DS_Error)
+      pImpl->DiagHandler->HasErrors = true;
----------------
MaskRay wrote:

I've considered this choice. Currently,

* LLVMContext::diagnose and handleDiagnostics need to cooperate and handle part of the process.
* handleDiagnostics is only called by LLVMContext::diagnose.

If we call `handleDiagnostics` in more places, it's clear that we need to duplicate some code in `diagnose` to the new call site, at least the `LLVMRemarkStreamer` stuff. Therefore, adding a new method to DiagnosticHandler does not abstract away things, and do not make things less error-prone.

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


More information about the cfe-commits mailing list