Skip to content

Commit 005948a

Browse files
committed
[DebugInfo] Fix LoadableByAddress losing debug info
LoadableByAddress was losing debug info, including at -Onone. When converting a load-store pair to a copy_addr, the debug info attached to the load was not salvaged. Additionally, the wrong scope was being attached to other debug values. (cherry picked from commit 644509e)
1 parent 08f49a4 commit 005948a

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
3434
#include "swift/SILOptimizer/PassManager/Transforms.h"
3535
#include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h"
36+
#include "swift/SILOptimizer/Utils/DebugOptUtils.h"
3637
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
3738
#include "swift/SILOptimizer/Utils/StackNesting.h"
3839
#include "llvm/ADT/MapVector.h"
@@ -1777,7 +1778,7 @@ static void rewriteUsesOfSscalar(StructLoweringState &pass,
17771778
createOutlinedCopyCall(copyBuilder, address, dest, pass);
17781779
storeUser->eraseFromParent();
17791780
} else if (auto *dbgInst = dyn_cast<DebugValueInst>(user)) {
1780-
SILBuilderWithScope dbgBuilder(dbgInst);
1781+
SILBuilder dbgBuilder(dbgInst, dbgInst->getDebugScope());
17811782
// Rewrite the debug_value to point to the variable in the alloca.
17821783
dbgBuilder.createDebugValueAddr(dbgInst->getLoc(), address,
17831784
*dbgInst->getVarInfo());
@@ -2150,9 +2151,8 @@ static void rewriteFunction(StructLoweringState &pass,
21502151
} else {
21512152
assert(currOperand->getType().isAddress() &&
21522153
"Expected an address type");
2153-
SILBuilderWithScope debugBuilder(instr);
21542154
// SILBuilderWithScope skips over metainstructions.
2155-
debugBuilder.setCurrentDebugScope(instr->getDebugScope());
2155+
SILBuilder debugBuilder(instr, instr->getDebugScope());
21562156
debugBuilder.createDebugValueAddr(instr->getLoc(), currOperand,
21572157
*instr->getVarInfo());
21582158
instr->getParent()->erase(instr);
@@ -3637,6 +3637,7 @@ class AssignAddressToDef : SILInstructionVisitor<AssignAddressToDef> {
36373637

36383638
builder.createCopyAddr(load->getLoc(), load->getOperand(), addr, IsTake,
36393639
IsInitialization);
3640+
swift::salvageLoadDebugInfo(load);
36403641
assignment.markForDeletion(load);
36413642
}
36423643

test/DebugInfo/LoadableByAddress.sil

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %target-sil-opt -loadable-address %s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
struct X {
9+
var x1 : Int
10+
var x2 : Int
11+
var x3 : Int
12+
var x4: Int
13+
var x5: Int
14+
var x6: Int
15+
var x7: Int
16+
var x8: Int
17+
var x9: Int
18+
var x10: Int
19+
var x11: Int
20+
var x12: Int
21+
var x13: Int
22+
var x14: Int
23+
var x15: Int
24+
var x16: Int
25+
}
26+
27+
28+
// CHECK: sil @test1 : $@convention(thin) () -> () {
29+
// CHECK: bb0:
30+
// CHECK: %0 = alloc_stack $Optional<X>
31+
// CHECK: %1 = alloc_stack $X
32+
// CHECK: %2 = alloc_stack $X
33+
// CHECK: %3 = alloc_stack $Optional<X>
34+
// CHECK: debug_value %{{[0-9]+}} : $*X, let, name "temp"
35+
// CHECK: } // end sil function 'test1'
36+
37+
sil @test1 : $@convention(thin) () -> () {
38+
bb0:
39+
%0 = alloc_stack $X
40+
%1 = alloc_stack $Optional<X>
41+
%2 = load %0 : $*X
42+
debug_value %2 : $X, let, name "temp"
43+
%3 = enum $Optional<X>, #Optional.some!enumelt, %2 : $X
44+
store %3 to %1 : $*Optional<X>
45+
dealloc_stack %1 : $*Optional<X>
46+
dealloc_stack %0 : $*X
47+
%t = tuple ()
48+
return %t : $()
49+
}

0 commit comments

Comments
 (0)