[llvm] Fix incorrect debug attribution for inlined allocas (PR #144345)
Shivam Kunwar via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 05:49:15 PDT 2025
https://github.com/phyBrackets created https://github.com/llvm/llvm-project/pull/144345
Fixing #142662
Fix incorrect debug attribution for inlined allocas, Clear debug locations from all inlined alloca instructions to prevent stack protection and other generated code from inheriting incorrect source line attributions from the callee function.
>From c7e92da3b925b2e9c6f5b4504e477c400a6a6c17 Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Mon, 16 Jun 2025 18:14:31 +0530
Subject: [PATCH] Fix incorrect debug attribution for inlined allocas
---
llvm/lib/Transforms/Utils/InlineFunction.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 21467a909af10..312b4888ee6e7 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2703,6 +2703,16 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Remember the first block that is newly cloned over.
FirstNewBlock = LastBlock; ++FirstNewBlock;
+ // Clear debug locations for all inlined allocas to prevent stack protection
+ // code from inheriting incorrect source attribution
+ for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E; ++BB) {
+ for (BasicBlock::iterator I = BB->begin(), IE = BB->end(); I != IE; ++I) {
+ if (auto *AI = dyn_cast<AllocaInst>(I)) {
+ AI->setDebugLoc(DebugLoc());
+ }
+ }
+ }
+
// Insert retainRV/clainRV runtime calls.
objcarc::ARCInstKind RVCallKind = objcarc::getAttachedARCFunctionKind(&CB);
if (RVCallKind != objcarc::ARCInstKind::None)
More information about the llvm-commits
mailing list