Skip to content

[SelectionDAG] [KCFI] Allow "kcfi" on invoke #148742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Jul 14, 2025

This is handled in CallBase, so it is valid for both call and invoke

Created using spr 1.3.4
@fmayer fmayer changed the title [SelectionDAG] Allow "kcfi" on invoke [SelectionDAG] [KCFI] Allow "kcfi" on invoke Jul 14, 2025
@fmayer fmayer requested a review from pcc July 14, 2025 22:40
@fmayer fmayer marked this pull request as ready for review July 14, 2025 22:40
@llvmbot llvmbot added backend:X86 llvm:SelectionDAG SelectionDAGISel as well labels Jul 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-x86

Author: Florian Mayer (fmayer)

Changes

This is handled in CallBase, so it is valid for both call and invoke


Full diff: https://github.com/llvm/llvm-project/pull/148742.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+1-1)
  • (modified) llvm/test/CodeGen/X86/kcfi.ll (+23)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index ecd1ff87e7fbc..517743aca7463 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3355,7 +3355,7 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
           {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
            LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
            LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
-           LLVMContext::OB_clang_arc_attachedcall}))
+           LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi}))
     reportFatalUsageError(
         "cannot lower invokes with arbitrary operand bundles!");
 
diff --git a/llvm/test/CodeGen/X86/kcfi.ll b/llvm/test/CodeGen/X86/kcfi.ll
index 059efcc71b0eb..fd93b8e3d4188 100644
--- a/llvm/test/CodeGen/X86/kcfi.ll
+++ b/llvm/test/CodeGen/X86/kcfi.ll
@@ -138,6 +138,29 @@ define void @f8() {
   ret void
 }
 
+declare i32 @__gxx_personality_v0(...)
+
+define void @f9() personality ptr @__gxx_personality_v0 {
+; MIR-LABEL: name: f9
+; MIR: body:
+; ISEL: CALL64m killed %0, 1, $noreg, 0, $noreg, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 12345678
+; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg
+; KCFI-NEXT:  BUNDLE{{.*}} {
+; KCFI-NEXT:    KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags
+; KCFI-NEXT:    CALL64r internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
+; KCFI-NEXT:  }
+  %1 = load ptr, ptr @g, align 8
+  invoke void %1() [ "kcfi"(i32 12345678) ]
+    to label %cont
+    unwind label %err
+cont:
+  ret void
+err:
+  %exn = landingpad { i8*, i32 }
+          catch i8* null
+  resume { i8*, i32 } %exn
+}
+
 attributes #0 = { "target-features"="+retpoline-indirect-branches,+retpoline-indirect-calls" }
 
 !llvm.module.flags = !{!0}

@fmayer fmayer marked this pull request as draft July 14, 2025 22:58
@fmayer fmayer marked this pull request as ready for review July 14, 2025 22:59
@fmayer fmayer merged commit 14dc3e3 into main Jul 15, 2025
16 checks passed
@fmayer fmayer deleted the users/fmayer/spr/selectiondag-allow-kcfi-on-invoke-1 branch July 15, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants