[clang] Add support for builtin_verbose_trap (PR #79230)

Dan Liew via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 14:10:19 PST 2024


================
@@ -3452,6 +3452,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
   case Builtin::BI__builtin_trap:
     EmitTrapCall(Intrinsic::trap);
     return RValue::get(nullptr);
+  case Builtin::BI__builtin_verbose_trap: {
+    llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation();
+    if (getDebugInfo()) {
+      std::string Str;
+      E->getArg(0)->tryEvaluateString(Str, getContext());
+      TrapLocation =
+          getDebugInfo()->CreateTrapFailureMessageFor(TrapLocation, Str);
+    }
+    ApplyDebugLocation ApplyTrapDI(*this, TrapLocation);
+    EmitTrapCall(Intrinsic::trap);
----------------
delcypher wrote:

We aren't doing anything here to prevent traps being merged that have either or different or same traps reasons.

We could support the following modes:

1. Merge all traps (this will drop the trap reason from the debug info). Good for code size, terrible for debugging
2. Prevent merging traps with different trap reasons. Good for debugging, not good for code size.
3. Prevent merging traps, even ones with the same trap reason. Even better for debugging because we can see in the debugger exactly where the trap came from. Even worse for code size.

I think it would be good to have a front end flag to control this.

I would be fine with you tackling this in a separate patch.


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


More information about the cfe-commits mailing list