[Lldb-commits] [clang] [lldb] [UBSan][BoundsSafety] Implement support for more expressive "trap reasons" (PR #154618)

via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 20 20:22:28 PDT 2025


================
@@ -1534,6 +1535,72 @@ inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
   return Report(SourceLocation(), DiagID);
 }
 
+//===----------------------------------------------------------------------===//
+// RuntimeTrapDiagnosticBuilder
+//===----------------------------------------------------------------------===//
+/// Class to make it convenient to construct "trap reasons" to attach to trap
+/// instructions.
+///
+/// Although this class inherits from `DiagnosticBuilder` it has very different
+/// semantics.
+///
+/// * This class should only be used with trap diagnostics (declared in
+/// `DiagnosticCodeGenKinds.td`).
+/// * The `RuntimeTrapDiagnosticBuilder` does not emit diagnostics to the normal
+///   diagnostics consumers on destruction like normal Diagnostic builders.
+///   Instead it does nothing on destruction.
+/// * Users of this class that want to retrieve the "trap reason" should call
+///   call the `getMessage()` and `getCategory()` and use those results before
+///   the builder is destroyed.
+/// * Unlike the `DiagnosticBuilder` the `RuntimeDiagnosticBuilder` should never
+/// be created as a temporary (i.e. rvalue) and instead should be stored. This
----------------
Sirraide wrote:

Making this class `[[nodiscard]]` would help avoid that.

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


More information about the lldb-commits mailing list