Skip to content

Commit

Permalink
[LLVM][Coroutines] Check variable decl scope instead of optimization …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
zyx-billy committed May 23, 2024
1 parent 729403e commit 910292c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2974,10 +2974,12 @@ void coro::salvageDebugInfo(
std::optional<BasicBlock::iterator> InsertPt;
if (auto *I = dyn_cast<Instruction>(Storage)) {
InsertPt = I->getInsertionPointAfterDef();
// Update DILocation only in O0 since it is easy to get out of sync in
// optimizations. See https://github.com/llvm/llvm-project/pull/75104 for
// an example.
if (!OptimizeFrame && I->getDebugLoc())
// Update DILocation only if variable was not inlined.
DebugLoc ILoc = I->getDebugLoc();
DebugLoc DVILoc = DVI.getDebugLoc();
if (ILoc && DVILoc &&
DVILoc->getScope()->getSubprogram() ==
ILoc->getScope()->getSubprogram())
DVI.setDebugLoc(I->getDebugLoc());
} else if (isa<Argument>(Storage))
InsertPt = F->getEntryBlock().begin();
Expand Down Expand Up @@ -3014,11 +3016,13 @@ void coro::salvageDebugInfo(
std::optional<BasicBlock::iterator> InsertPt;
if (auto *I = dyn_cast<Instruction>(Storage)) {
InsertPt = I->getInsertionPointAfterDef();
// Update DILocation only in O0 since it is easy to get out of sync in
// optimizations. See https://github.com/llvm/llvm-project/pull/75104 for
// an example.
if (!OptimizeFrame && I->getDebugLoc())
DVR.setDebugLoc(I->getDebugLoc());
// Update DILocation only if variable was not inlined.
DebugLoc ILoc = I->getDebugLoc();
DebugLoc DVRLoc = DVR.getDebugLoc();
if (ILoc && DVRLoc &&
DVRLoc->getScope()->getSubprogram() ==
ILoc->getScope()->getSubprogram())
DVR.setDebugLoc(ILoc);
} else if (isa<Argument>(Storage))
InsertPt = F->getEntryBlock().begin();
if (InsertPt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -passes='module(coro-early),cgscc(inline,coro-split<reuse-storage>)' -S | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(inline,coro-split<reuse-storage>)' -S | FileCheck %s
; RUN: opt < %s -passes='module(coro-early),cgscc(inline,coro-split)' -S | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(inline,coro-split)' -S | FileCheck %s

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

0 comments on commit 910292c

Please sign in to comment.