Skip to content

Commit be6b4f6

Browse files
authored
[HLSL][SPIRV] Fix calling convention for call in entry function. (#110542)
Fix the calling convention used for the call in the entry point wrapper. No calling convention is currently set. It can easily use the calling convention of the function that is being called. Without this, there is a mismatch in the calling convention between the call site and the callee. This is undefined behaviour.
1 parent 2672037 commit be6b4f6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
415415
}
416416

417417
CallInst *CI = B.CreateCall(FunctionCallee(Fn), Args);
418-
(void)CI;
418+
CI->setCallingConv(Fn->getCallingConv());
419419
// FIXME: Handle codegen for return type semantics.
420420
// See: https://github.com/llvm/llvm-project/issues/57875
421421
B.CreateRetVoid();

clang/test/CodeGenHLSL/semantics/DispatchThreadID.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// CHECK: define void @foo()
77
// CHECK-DXIL: %[[#ID:]] = call i32 @llvm.[[TARGET]].thread.id(i32 0)
88
// CHECK-SPIRV: %[[#ID:]] = call i32 @llvm.[[TARGET]].thread.id(i32 0)
9-
// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]])
9+
// CHECK-DXIL: call void @{{.*}}foo{{.*}}(i32 %[[#ID]])
10+
// CHECK-SPIRV: call spir_func void @{{.*}}foo{{.*}}(i32 %[[#ID]])
1011
[shader("compute")]
1112
[numthreads(8,8,1)]
1213
void foo(uint Idx : SV_DispatchThreadID) {}
@@ -17,6 +18,7 @@ void foo(uint Idx : SV_DispatchThreadID) {}
1718
// CHECK: %[[#ID_Y:]] = call i32 @llvm.[[TARGET]].thread.id(i32 1)
1819
// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1
1920
// CHECK-DXIL: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
21+
// CHECK-SPIRV: call spir_func void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]])
2022
[shader("compute")]
2123
[numthreads(8,8,1)]
2224
void bar(uint2 Idx : SV_DispatchThreadID) {}

0 commit comments

Comments
 (0)