Skip to content

Commit dd8d5b8

Browse files
authored
Merge pull request #41521 from gottesmm/pr-7a4df70e3efbb5bb8a409952b2381683166cea37
[move-function-value] Make sure that we propagate the debug scope from our original debug value into new undef debug values.
2 parents 210e135 + 0f67926 commit dd8d5b8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ bool MoveKillsCopyableValuesChecker::check() {
400400
// Then look at all of our found consuming uses. See if any of these are
401401
// _move that are within the boundary.
402402
bool foundMove = false;
403-
auto dbgVarInfo = DebugVarCarryingInst::getFromValue(lexicalValue);
404-
StringRef varName = DebugVarCarryingInst::getName(dbgVarInfo);
403+
auto dbgVarInst = DebugVarCarryingInst::getFromValue(lexicalValue);
404+
StringRef varName = DebugVarCarryingInst::getName(dbgVarInst);
405405
for (auto *use : livenessInfo.consumingUse) {
406406
if (auto *mvi = dyn_cast<MoveValueInst>(use->getUser())) {
407407
// Only emit diagnostics if our move value allows us to.
@@ -420,14 +420,16 @@ bool MoveKillsCopyableValuesChecker::check() {
420420
emittedDiagnostic = true;
421421
} else {
422422
LLVM_DEBUG(llvm::dbgs() << " WithinBoundary: No!\n");
423-
if (auto varInfo = dbgVarInfo.getVarInfo()) {
424-
successMovesDbgInfoCarryingInsts.push_back(*dbgVarInfo);
423+
if (auto varInfo = dbgVarInst.getVarInfo()) {
424+
successMovesDbgInfoCarryingInsts.push_back(*dbgVarInst);
425425
auto *next = mvi->getNextInstruction();
426426
SILBuilderWithScope builder(next);
427-
// Use an autogenerated location to ensure that if we are next to a
428-
// terminator, we don't assert.
427+
// We need to make sure any undefs we put in are the same loc/debug
428+
// scope as our original so that the backend treats them as
429+
// referring to the same "debug entity".
430+
builder.setCurrentDebugScope(dbgVarInst->getDebugScope());
429431
builder.createDebugValue(
430-
dbgVarInfo.inst->getLoc(),
432+
dbgVarInst->getLoc(),
431433
SILUndef::get(mvi->getOperand()->getType(), mod), *varInfo,
432434
false /*poison*/, true /*moved*/);
433435
}
@@ -439,7 +441,7 @@ bool MoveKillsCopyableValuesChecker::check() {
439441
// If we found a move, mark our debug var inst as having a moved value. This
440442
// ensures we emit llvm.dbg.addr instead of llvm.dbg.declare in IRGen.
441443
if (foundMove) {
442-
dbgVarInfo.markAsMoved();
444+
dbgVarInst.markAsMoved();
443445
}
444446
}
445447

test/DebugInfo/move_function_dbginfo.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ public func addressOnlyVarTest<T : P>(_ x: T) {
240240
// Conditional Tests //
241241
///////////////////////
242242

243+
// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo23copyableValueCCFlowTestyyF"(
244+
// CHECK: call void @llvm.dbg.addr(metadata %T21move_function_dbginfo5KlassC** %k.debug, metadata ![[K_COPYABLE_LET_CCFLOW_METADATA:[0-9]+]], metadata !DIExpression()), !dbg ![[ADDR_LOC:[0-9]+]]
245+
// CHECK-NEXT: br label %[[NEXT_BB:[0-9]+]],
246+
//
247+
// CHECK: [[NEXT_BB]]:
248+
// CHECK: br i1 {{%[0-9]+}}, label %[[LHS:[0-9]+]], label %[[RHS:[0-9]+]],
249+
//
250+
// CHECK: [[LHS]]:
251+
// CHECK: call void @llvm.dbg.value(metadata %T21move_function_dbginfo5KlassC* undef, metadata ![[K_COPYABLE_LET_CCFLOW_METADATA]], metadata !DIExpression()), !dbg ![[ADDR_LOC]]
252+
public func copyableValueCCFlowTest() {
253+
let k = Klass()
254+
k.doSomething()
255+
if trueValue {
256+
let m = _move(k)
257+
m.doSomething()
258+
}
259+
}
260+
243261
// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo037copyableVarTestCCFlowReinitOutOfBlockF0yyF"(
244262
// CHECK: call void @llvm.dbg.declare(metadata %T21move_function_dbginfo5KlassC** %m.debug,
245263
// CHECK: call void @llvm.dbg.addr(metadata %T21move_function_dbginfo5KlassC** %k, metadata ![[K_COPYABLE_VAR_CCFLOW_REINIT_OUT_BLOCK_METADATA:[0-9]+]], metadata !DIExpression()), !dbg ![[ADDR_LOC:[0-9]*]]
@@ -385,3 +403,4 @@ public func addressOnlyVarTestCCFlowReinitInBlockTest<T : P>(_ x: T.Type) {
385403
// CHECK-DAG: ![[K_COPYABLE_VAR_CCFLOW_REINIT_IN_BLOCK_METADATA]] = !DILocalVariable(name: "k",
386404
// CHECK-DAG: ![[K_ADDRESSONLY_VAR_CCFLOW_REINIT_OUT_BLOCK_METADATA]] = !DILocalVariable(name: "k",
387405
// CHECK-DAG: ![[K_ADDRESSONLY_VAR_CCFLOW_REINIT_IN_BLOCK_METADATA]] = !DILocalVariable(name: "k",
406+
// CHECK-DAG: ![[K_COPYABLE_LET_CCFLOW_METADATA]] = !DILocalVariable(name: "k",

0 commit comments

Comments
 (0)