From a8a00848e117664b7c6123a0303444db829b89bb Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 16 Jun 2025 08:27:57 +0200 Subject: [PATCH] Update debug info when changing CC to Fast This fixes #144301 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 7db0586386506..b0f1dee415efd 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1920,6 +1920,14 @@ static void RemovePreallocated(Function *F) { } } +static unsigned char GetDebugInfoFastCC(const Triple &Triple) { + if (Triple.isOSWindows() && Triple.isArch32Bit()) { + return llvm::dwarf::DW_CC_BORLAND_msfastcall; + } + + return llvm::dwarf::DW_CC_normal; +} + static bool OptimizeFunctions(Module &M, function_ref GetTLI, @@ -1938,6 +1946,9 @@ OptimizeFunctions(Module &M, if (hasOnlyColdCalls(F, GetBFI, ChangeableCCCache)) AllCallsCold.push_back(&F); + unsigned char DebugInfoFastCC = + GetDebugInfoFastCC(Triple(M.getTargetTriple())); + // Optimize functions. for (Function &F : llvm::make_early_inc_range(M)) { // Don't perform global opt pass on naked functions; we don't want fast @@ -2021,6 +2032,13 @@ OptimizeFunctions(Module &M, // Fast calling convention. F.setCallingConv(CallingConv::Fast); ChangeCalleesToFastCall(&F); + + if (F.getSubprogram()) { + DISubprogram *SP = F.getSubprogram(); + auto Temp = SP->getType()->cloneWithCC(DebugInfoFastCC); + SP->replaceType(MDNode::replaceWithPermanent(std::move(Temp))); + } + ++NumFastCallFns; Changed = true; }