================ @@ -793,6 +795,36 @@ DiagnosticBuilder::DiagnosticBuilder(const DiagnosticBuilder &D) D.Clear(); } +RuntimeTrapDiagnosticBuilder::RuntimeTrapDiagnosticBuilder( + DiagnosticsEngine *DiagObj, unsigned DiagID, TrapReason &TR) + : DiagnosticBuilder(DiagObj, SourceLocation(), DiagID), TR(TR) { + assert(DiagObj->getDiagnosticIDs()->isTrapDiag(DiagID)); +} + +RuntimeTrapDiagnosticBuilder::~RuntimeTrapDiagnosticBuilder() { + // Store the trap message and category into the TrapReason object. + getMessage(TR.Message); + TR.Category = getCategory(); + + // Make sure that when `DiagnosticBuilder::~DiagnosticBuilder()` + // calls `Emit()` that it does nothing. + Clear(); +} + +void RuntimeTrapDiagnosticBuilder::getMessage(SmallVectorImpl<char> &Storage) { + // Render the Diagnostic + Diagnostic Info(DiagObj, *this); + Info.FormatDiagnostic(Storage); +} + +StringRef RuntimeTrapDiagnosticBuilder::getCategory() { + auto CategoryID = + DiagObj->getDiagnosticIDs()->getCategoryNumberForDiag(DiagID); + if (CategoryID == 0) + return ""; ---------------- Sirraide wrote:
```suggestion ``` I don’t think this check is even necessary since `getCategoryNameFromID()` already returns an empty `StringRef` if the ID is invalid. Side note: The comment on `getCategoryNameFromID()` needs updating because it mentions returning ‘null’, even though that doesn’t make sense for a `StringRef`; it used to return a `const char*` and it seems that whoever refactored it forgot to update the comment. https://github.com/llvm/llvm-project/pull/154618 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits