[Lldb-commits] [clang] [lldb] [UBSan][BoundsSafety] Implement support for more expressive "trap reasons" (PR #154618)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Aug 23 04:35:32 PDT 2025
================
@@ -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
More information about the lldb-commits
mailing list