Skip to content

[move-function-value] Make sure that we propagate the debug scope from our original debug value into new undef debug values. #41521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/SILOptimizer/Mandatory/MoveKillsCopyableValuesChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ bool MoveKillsCopyableValuesChecker::check() {
// Then look at all of our found consuming uses. See if any of these are
// _move that are within the boundary.
bool foundMove = false;
auto dbgVarInfo = DebugVarCarryingInst::getFromValue(lexicalValue);
StringRef varName = DebugVarCarryingInst::getName(dbgVarInfo);
auto dbgVarInst = DebugVarCarryingInst::getFromValue(lexicalValue);
StringRef varName = DebugVarCarryingInst::getName(dbgVarInst);
for (auto *use : livenessInfo.consumingUse) {
if (auto *mvi = dyn_cast<MoveValueInst>(use->getUser())) {
// Only emit diagnostics if our move value allows us to.
Expand All @@ -420,14 +420,16 @@ bool MoveKillsCopyableValuesChecker::check() {
emittedDiagnostic = true;
} else {
LLVM_DEBUG(llvm::dbgs() << " WithinBoundary: No!\n");
if (auto varInfo = dbgVarInfo.getVarInfo()) {
successMovesDbgInfoCarryingInsts.push_back(*dbgVarInfo);
if (auto varInfo = dbgVarInst.getVarInfo()) {
successMovesDbgInfoCarryingInsts.push_back(*dbgVarInst);
auto *next = mvi->getNextInstruction();
SILBuilderWithScope builder(next);
// Use an autogenerated location to ensure that if we are next to a
// terminator, we don't assert.
// We need to make sure any undefs we put in are the same loc/debug
// scope as our original so that the backend treats them as
// referring to the same "debug entity".
builder.setCurrentDebugScope(dbgVarInst->getDebugScope());
builder.createDebugValue(
dbgVarInfo.inst->getLoc(),
dbgVarInst->getLoc(),
SILUndef::get(mvi->getOperand()->getType(), mod), *varInfo,
false /*poison*/, true /*moved*/);
}
Expand All @@ -439,7 +441,7 @@ bool MoveKillsCopyableValuesChecker::check() {
// If we found a move, mark our debug var inst as having a moved value. This
// ensures we emit llvm.dbg.addr instead of llvm.dbg.declare in IRGen.
if (foundMove) {
dbgVarInfo.markAsMoved();
dbgVarInst.markAsMoved();
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/DebugInfo/move_function_dbginfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ public func addressOnlyVarTest<T : P>(_ x: T) {
// Conditional Tests //
///////////////////////

// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo23copyableValueCCFlowTestyyF"(
// 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]+]]
// CHECK-NEXT: br label %[[NEXT_BB:[0-9]+]],
//
// CHECK: [[NEXT_BB]]:
// CHECK: br i1 {{%[0-9]+}}, label %[[LHS:[0-9]+]], label %[[RHS:[0-9]+]],
//
// CHECK: [[LHS]]:
// CHECK: call void @llvm.dbg.value(metadata %T21move_function_dbginfo5KlassC* undef, metadata ![[K_COPYABLE_LET_CCFLOW_METADATA]], metadata !DIExpression()), !dbg ![[ADDR_LOC]]
public func copyableValueCCFlowTest() {
let k = Klass()
k.doSomething()
if trueValue {
let m = _move(k)
m.doSomething()
}
}

// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo037copyableVarTestCCFlowReinitOutOfBlockF0yyF"(
// CHECK: call void @llvm.dbg.declare(metadata %T21move_function_dbginfo5KlassC** %m.debug,
// 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]*]]
Expand Down Expand Up @@ -385,3 +403,4 @@ public func addressOnlyVarTestCCFlowReinitInBlockTest<T : P>(_ x: T.Type) {
// CHECK-DAG: ![[K_COPYABLE_VAR_CCFLOW_REINIT_IN_BLOCK_METADATA]] = !DILocalVariable(name: "k",
// CHECK-DAG: ![[K_ADDRESSONLY_VAR_CCFLOW_REINIT_OUT_BLOCK_METADATA]] = !DILocalVariable(name: "k",
// CHECK-DAG: ![[K_ADDRESSONLY_VAR_CCFLOW_REINIT_IN_BLOCK_METADATA]] = !DILocalVariable(name: "k",
// CHECK-DAG: ![[K_COPYABLE_LET_CCFLOW_METADATA]] = !DILocalVariable(name: "k",