Skip to content

Commit 3003155

Browse files
authored
Merge pull request #73404 from Snowy1803/phixpansion
[DebugInfo] Fix PhiExpansion losing debug info
2 parents 9e2c13b + b944e38 commit 3003155

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/SILOptimizer/Transforms/PhiArgumentOptimizations.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ bool PhiExpansionPass::optimizeArg(SILPhiArgument *initialArg) {
439439
}
440440

441441
for (DebugValueInst *dvi : debugValueUsers) {
442+
// Recreate the debug_value with a fragment.
443+
SILBuilder B(dvi, dvi->getDebugScope());
444+
SILDebugVariable var = *dvi->getVarInfo();
445+
if (!var.Type)
446+
var.Type = initialArg->getType();
447+
var.DIExpr.append(SILDebugInfoExpression::createFragment(field));
448+
B.createDebugValue(dvi->getLoc(), dvi->getOperand(), var);
442449
dvi->eraseFromParent();
443450
}
444451
for (StructExtractInst *sei : structExtractUsers) {

test/DebugInfo/phi-expansion.sil

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-sil-opt %s -phi-expansion | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Swift
6+
7+
struct Mystruct {
8+
var i: Int
9+
var j: Int
10+
}
11+
12+
// CHECK-LABEL: sil @test_simple
13+
// CHECK: br bb3(%{{[0-9]*}} : $Int)
14+
// CHECK: bb3(%[[PHI:[0-9]*]] : $Int):
15+
// CHECK: debug_value %[[PHI]] : $Int, let, name "pos", type $Mystruct, expr op_fragment:#Mystruct.i
16+
// CHECK: } // end sil function 'test_simple'
17+
18+
sil @test_simple : $@convention(thin) (Mystruct, Mystruct) -> Int {
19+
bb0(%0 : $Mystruct, %1 : $Mystruct):
20+
cond_br undef, bb1, bb2
21+
22+
bb1:
23+
br bb3(%0 : $Mystruct)
24+
25+
bb2:
26+
br bb3(%1 : $Mystruct)
27+
28+
bb3(%5 : $Mystruct):
29+
debug_value %5 : $Mystruct, let, name "pos"
30+
%6 = struct_extract %5 : $Mystruct, #Mystruct.i
31+
return %6 : $Int
32+
}

0 commit comments

Comments
 (0)