Skip to content

Commit caa9758

Browse files
committed
[addr-move-function] Make sure to insert the debug_value for a reinit /after/ the reinit.
Otherwise, the memory lifetime verifier complains we are using the value while it is not initialized. I actually did this correctly in the single block impl. Just a small thinko.
1 parent 32fceb5 commit caa9758

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/SILOptimizer/Mandatory/MoveKillsCopyableAddressesChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,9 @@ bool DataflowState::cleanupAllDestroyAddr(
15391539
// Make sure to create a new debug_value for the reinit value.
15401540
if (addressDebugInst) {
15411541
if (auto varInfo = addressDebugInst.getVarInfo()) {
1542-
SILBuilderWithScope reinitBuilder(*reinit);
1542+
// We need to always insert /after/ the reinit since the value will not
1543+
// be defined before the value.
1544+
SILBuilderWithScope reinitBuilder((*reinit)->getNextInstruction());
15431545
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
15441546
reinitBuilder.createDebugValue(
15451547
addressDebugInst.inst->getLoc(), address, *varInfo, false,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -enable-experimental-move-only %s -parse-stdlib -emit-sil -o /dev/null
2+
3+
// REQUIRES: optimized_stdlib
4+
5+
import Swift
6+
7+
var booleanValue: Bool { true }
8+
9+
public class Klass {
10+
func doSomething() { print("something") }
11+
}
12+
13+
14+
// Make sure we put the dbg_info after the reinit, not before it. Otherwise this
15+
// test case crashes b/c we are using the value before it is reinited.
16+
public func copyableVarArgTestCCFlowReinitOutOfBlockTest(_ k: inout Klass) {
17+
k.doSomething()
18+
if booleanValue {
19+
let m = _move(k)
20+
m.doSomething()
21+
}
22+
k = Klass()
23+
k.doSomething()
24+
}
25+

0 commit comments

Comments
 (0)