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

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 4 20:35:48 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);
----------------
ahatanak wrote:

I can tackle it in a separate patch.

For mode 2 and 3 calls, we can annotate the calls with something that indicates whether they can be merged only with other calls if the reason is the same or they cannot be merged at all. For calls in mode 3, we can just annotate the calls with attribute `nomerge`. For mode 2, I think we need to annotate the calls with an attribute or something that distinguishes the calls from the calls that are mergeable (mode 1) and the ones that aren't (mode 3).

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


More information about the cfe-commits mailing list