From 52b07d971c89ab8fbcc497f22c43931b488256ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Tue, 17 Dec 2024 13:26:03 +0100 Subject: [HLSL] Fix call convention mismatch for ctor/dtor (#118651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, there was a calling-convention mismatch between the constructors and the actual call emitted for the entrypoint wrapper. Such mismatch causes the InstCombine pass to replace this call with an `unreachable`, breaking the whole function. Signed-off-by: Nathan Gauër --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index fb15b19..c354e58 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -512,13 +512,17 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() { IP = Token->getNextNode(); } IRBuilder<> B(IP); - for (auto *Fn : CtorFns) - B.CreateCall(FunctionCallee(Fn), {}, OB); + for (auto *Fn : CtorFns) { + auto CI = B.CreateCall(FunctionCallee(Fn), {}, OB); + CI->setCallingConv(Fn->getCallingConv()); + } // Insert global dtors before the terminator of the last instruction B.SetInsertPoint(F.back().getTerminator()); - for (auto *Fn : DtorFns) - B.CreateCall(FunctionCallee(Fn), {}, OB); + for (auto *Fn : DtorFns) { + auto CI = B.CreateCall(FunctionCallee(Fn), {}, OB); + CI->setCallingConv(Fn->getCallingConv()); + } } // No need to keep global ctors/dtors for non-lib profile after call to -- cgit v1.1