Skip to content

Commit 910292c

Browse files
authored
[LLVM][Coroutines] Check variable decl scope instead of optimization level for hoisted DbgDeclare Loc (#92978)
Minor patch following up on #75402. The more generalized version of [this error](#75104 (comment)) is whenever we have a debug variable created in one subprogram scope inlined into another subprogram scope. So instead of checking optimization level, it is safer to just check whether the subprogram scope of the variable matches the subprogram scope of the hoisted position.
1 parent 729403e commit 910292c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,10 +2974,12 @@ void coro::salvageDebugInfo(
29742974
std::optional<BasicBlock::iterator> InsertPt;
29752975
if (auto *I = dyn_cast<Instruction>(Storage)) {
29762976
InsertPt = I->getInsertionPointAfterDef();
2977-
// Update DILocation only in O0 since it is easy to get out of sync in
2978-
// optimizations. See https://github.com/llvm/llvm-project/pull/75104 for
2979-
// an example.
2980-
if (!OptimizeFrame && I->getDebugLoc())
2977+
// Update DILocation only if variable was not inlined.
2978+
DebugLoc ILoc = I->getDebugLoc();
2979+
DebugLoc DVILoc = DVI.getDebugLoc();
2980+
if (ILoc && DVILoc &&
2981+
DVILoc->getScope()->getSubprogram() ==
2982+
ILoc->getScope()->getSubprogram())
29812983
DVI.setDebugLoc(I->getDebugLoc());
29822984
} else if (isa<Argument>(Storage))
29832985
InsertPt = F->getEntryBlock().begin();
@@ -3014,11 +3016,13 @@ void coro::salvageDebugInfo(
30143016
std::optional<BasicBlock::iterator> InsertPt;
30153017
if (auto *I = dyn_cast<Instruction>(Storage)) {
30163018
InsertPt = I->getInsertionPointAfterDef();
3017-
// Update DILocation only in O0 since it is easy to get out of sync in
3018-
// optimizations. See https://github.com/llvm/llvm-project/pull/75104 for
3019-
// an example.
3020-
if (!OptimizeFrame && I->getDebugLoc())
3021-
DVR.setDebugLoc(I->getDebugLoc());
3019+
// Update DILocation only if variable was not inlined.
3020+
DebugLoc ILoc = I->getDebugLoc();
3021+
DebugLoc DVRLoc = DVR.getDebugLoc();
3022+
if (ILoc && DVRLoc &&
3023+
DVRLoc->getScope()->getSubprogram() ==
3024+
ILoc->getScope()->getSubprogram())
3025+
DVR.setDebugLoc(ILoc);
30223026
} else if (isa<Argument>(Storage))
30233027
InsertPt = F->getEntryBlock().begin();
30243028
if (InsertPt) {

llvm/test/Transforms/Coroutines/coro-debug-frame-variable-O1.ll renamed to llvm/test/Transforms/Coroutines/coro-debug-frame-variable-inlined.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt < %s -passes='module(coro-early),cgscc(inline,coro-split<reuse-storage>)' -S | FileCheck %s
2-
; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(inline,coro-split<reuse-storage>)' -S | FileCheck %s
1+
; RUN: opt < %s -passes='module(coro-early),cgscc(inline,coro-split)' -S | FileCheck %s
2+
; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(inline,coro-split)' -S | FileCheck %s
33

44
; Simplified version from pr#75104.
55
; Make sure we do not update debug location for hosited dbg.declare intrinsics when optimizing coro frame.

0 commit comments

Comments
 (0)