[llvm] [DebugInfo] Fix incorrect debug attribution for inlined allocas (PR #144345)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 11:22:13 PDT 2025


================
@@ -2703,6 +2703,17 @@ 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());
----------------
SLTozer wrote:

```suggestion
          AI->setDebugLoc(DebugLoc::getDropped());
          // or...
          AI->dropLocation();
```
Some recent changes have landed to better track missing debug locations - see [the docs](https://llvm.org/docs/HowToUpdateDebugInfo.html#setting-locations-for-new-instructions) and [this RFC](https://discourse.llvm.org/t/rfc-require-real-or-annotated-source-locations-on-all-instructions/86816) for more details, but the tl;dr is that instead of using `DebugLoc()` for empty locations we'd prefer an annotative location that categorizes the nature of the empty location.

https://github.com/llvm/llvm-project/pull/144345


More information about the llvm-commits mailing list