[clang] [CIR] Add CIRGen for cir.unreachable and cir.trap (PR #151363)

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 2 02:04:32 PDT 2025


================
@@ -1780,6 +1780,20 @@ LValue CIRGenFunction::emitLoadOfReferenceLValue(Address refAddr,
                         pointeeBaseInfo);
 }
 
+void CIRGenFunction::emitTrap(mlir::Location loc, bool createNewBlock) {
----------------
Lancern wrote:

I'd rather not do this change in this PR. The biggest reason is, in classic CodeGen, the sanitize calls for the unreachable emission in `emitImplicitReturn` are different from the sanitizer calls emitted in `emitUnreachable`, see https://godbolt.org/z/c1v9bnc8d:

- An explicit call to `__builtin_unreachable` emits sanitizer call to `__ubsan_handle_builtin_unreachable`, which is what will be emitted in `emitUnreachable`;
- A missing return in `emitImplicitReturn` emits sanitizer call to `__ubsan_handle_missing_return`.

`emitUnreachable` and `emitTrap` also (optionally) resets the insertion point of the IR builder, which is not that helpful for code in `emitImplicitReturn`.

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


More information about the cfe-commits mailing list