[Mlir-commits] [mlir] [docs]: Add a note about using custom types with diagnostics (PR #73818)

Jeremy Kun llvmlistbot at llvm.org
Wed Nov 29 08:47:23 PST 2023


https://github.com/j2kun created https://github.com/llvm/llvm-project/pull/73818

None

>From 7137d88e8b871c3b661d907a0c76a035b10e8f1c Mon Sep 17 00:00:00 2001
From: Jeremy Kun <jkun at google.com>
Date: Wed, 29 Nov 2023 08:46:49 -0800
Subject: [PATCH] add note about custom types with diagnostics

---
 mlir/docs/Diagnostics.md | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md
index 9819843c563ca48..82bc61dd8c3adfb 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -119,6 +119,14 @@ op->emitError() << anotherOp;
 op->emitRemark() << anotherOp;
 ```
 
+To make a custom type compatible with Diagnostics, one must implement the
+following friend function.
+
+```c++
+friend mlir::Diagnostic &operator<<(
+    mlir::Diagnostic &diagnostic, const MyType &foo);
+```
+
 ### Attaching notes
 
 Unlike many other compiler frameworks, notes in MLIR cannot be emitted directly.



More information about the Mlir-commits mailing list