[llvm] [X86] Emit LSDA call site info for inline asm calls marked `unwind` (PR #218276)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 03:59:43 PDT 2026


https://github.com/hsanzg updated https://github.com/llvm/llvm-project/pull/218276

>From d78e35546fcd1836b98f0ae933dab9ba9522a53a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Sanz=20Gonz=C3=A1lez?= <hugo at hgsg.me>
Date: Sun, 23 Aug 2026 02:22:30 +0200
Subject: [PATCH] Emit call site info for inline asm calls with `unwind`

Invokes for inline asm already emit the corresponding call site entry in
the LSDA. Do the same for regular inline asm `call`s that may unwind,
with a zero/continue landing pad address.
---
 llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp    |  5 +++
 .../X86/eh-call-site-info-for-inline-asm.ll   | 39 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 llvm/test/CodeGen/X86/eh-call-site-info-for-inline-asm.ll

diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index db6242e6523c0..9b2bb512d23ef 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -267,6 +267,11 @@ void EHStreamer::computeCallSiteTable(
       if (!MI.isEHLabel()) {
         if (MI.isCall())
           SawPotentiallyThrowing |= !callToNoUnwindFunction(&MI);
+        else if (MI.isInlineAsm()) {
+          // An inline asm call may unwind iff it contains the `unwind` keyword.
+          unsigned ExtraInfo = MI.getOperand(InlineAsm::MIOp_ExtraInfo).getImm();
+          SawPotentiallyThrowing |= ExtraInfo & InlineAsm::Extra_MayUnwind;
+        }
         continue;
       }
 
diff --git a/llvm/test/CodeGen/X86/eh-call-site-info-for-inline-asm.ll b/llvm/test/CodeGen/X86/eh-call-site-info-for-inline-asm.ll
new file mode 100644
index 0000000000000..40aaa73fa8f0b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/eh-call-site-info-for-inline-asm.ll
@@ -0,0 +1,39 @@
+; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s
+; Test that we emit call site info for inline asm calls that may unwind.
+
+declare i32 @__my_personality_v0(...)
+declare void @might_throw()
+
+define void @foo() personality ptr @__my_personality_v0 {
+; CHECK: .cfi_personality 3, __my_personality_v0
+; CHECK:      .Lcst_begin0:
+; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .Ltmp1-.Ltmp0
+; CHECK-NEXT: .uleb128 .Ltmp2-.Lfunc_begin0
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .uleb128 .Ltmp1-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .Lfunc_end0-.Ltmp1
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .byte   0
+; CHECK-NEXT: .Lcst_end0:
+
+    ; An inline asm call that may unwind but has no landing pad.
+    call void asm sideeffect alignstack inteldialect unwind "call ${0:P}", "X"(ptr @might_throw)
+
+    ; An inline asm invoke with a landing pad.
+    invoke void asm sideeffect alignstack inteldialect unwind
+        "call ${0:P}", "X"(ptr @might_throw)
+        to label %cont unwind label %lpad
+
+cont:
+    ret void
+
+lpad:
+    %eh = landingpad { ptr, i32 }
+            cleanup
+    resume { ptr, i32 } %eh
+}



More information about the llvm-commits mailing list