================ @@ -1534,6 +1536,103 @@ inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) { return Report(SourceLocation(), DiagID); } +//===----------------------------------------------------------------------===// +// RuntimeTrapDiagnosticBuilder and helper classes +//===----------------------------------------------------------------------===// + +/// Helper class for \class RuntimeTrapDiagnosticBuilder. This class stores the +/// "trap reason" built by \class RuntimeTrapDiagnosticBuilder. This consists of +/// a trap message and trap category. +/// +/// It is intended that this object be allocated on the stack. +class TrapReason { +public: + TrapReason() {} + /// \return The trap message. Note the lifetime of the underlying storage for + /// the returned StringRef lives in this class which means the returned + /// StringRef should not be used after this class is destroyed. + StringRef getMessage() const { return Message; } + + /// \return the trap category (e.g. "Undefined Behavior Sanitizer") + StringRef getCategory() const { return Category; } + + bool isEmpty() const { return Message.size() == 0 && Category.size() == 0; } + + /// \return a pointer to this object if it contains a non-empty trap reason, + /// otherwise return `nullptr`. This is a convenient helper for passing + /// TrapReason objects to function calls that have a `TrapReason*` parameter. + TrapReason *getPtr() { + if (isEmpty()) + return nullptr; + return this; + } ---------------- Sirraide wrote:
I don’t think this function is really necessary. Can’t we just have whatever function actually emits the diagnostic check if it’s empty? https://github.com/llvm/llvm-project/pull/154618 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits