[llvm] [SPIRV] Process indirect function calls immediately (PR #177222)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 07:49:28 PST 2026
================
@@ -0,0 +1,37 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
+; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; This test verifies that indirect calls with functions lacking return statements
+; are don't cause an error.
+
+; CHECK-DAG: OpCapability FunctionPointersINTEL
+; CHECK: OpExtension "SPV_INTEL_function_pointers"
+
+; CHECK-DAG: %[[TyVoid:.*]] = OpTypeVoid
+; CHECK-DAG: %[[TyInt32:.*]] = OpTypeInt 32 0
+
+; CHECK-DAG: %[[TyFun:.*]] = OpTypeFunction %[[TyVoid]] %[[TyInt32]] %[[TyInt32]]
+; CHECK-DAG: %[[TyPtrFun:.*]] = OpTypePointer CodeSectionINTEL %[[TyFun]]
+
+; CHECK: OpFunction
+; CHECK: %[[Load:.*]] = OpLoad %[[TyPtrFun]]
+; CHECK: FunctionPointerCallINTEL %[[TyVoid]] %[[Load]]
+
+%struct.ident_t = type { i32, i32, i32, i32, ptr addrspace(4) }
+
+ at 0 = addrspace(1) constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr addrspace(4) addrspacecast (ptr addrspace(1) null to ptr addrspace(4)) }
+
+define spir_func void @foo(ptr addrspace(4) %Ident) addrspace(9) {
+entry:
+ br label %do.body
+
+do.body: ; preds = %do.body, %entry
+ %0 = load ptr addrspace(9), ptr addrspace(4) null, align 8
----------------
sarnex wrote:
Yes, so here are the conditions for the bug to occur:
1) function a has an indirect call
2) function a does not have a return statement
3) function b contains some call (doesn't have to be indirect) that needs to be lowered
4) function b contains a return statement
the indirect call in condition 1) does not have to be calling function b, the map gets messed up no matter what function is being called indirectly.
https://github.com/llvm/llvm-project/pull/177222
More information about the llvm-commits
mailing list