Skip to content

Commit 288f4a1

Browse files
authored
Merge pull request swiftlang#19087 from adrian-prantl/37410759
2 parents 8614247 + 81f9ea3 commit 288f4a1

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ class TailAllocatedDebugVariable {
12701270
/// Returns the name of the source variable, if it is stored in the
12711271
/// instruction.
12721272
StringRef getName(const char *buf) const;
1273-
bool isLet() const { return Bits.Data.Constant; }
1273+
bool isLet() const { return Bits.Data.Constant; }
12741274

12751275
Optional<SILDebugVariable> get(VarDecl *VD, const char *buf) const {
12761276
if (!Bits.Data.HasValue)

lib/SILGen/SILGenProlog.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,16 @@ struct ArgumentInitHelper {
253253
// argument if we're responsible for it.
254254
}
255255
SGF.VarLocs[vd] = SILGenFunction::VarLoc::get(argrv.getValue());
256-
if (argrv.getType().isAddress())
257-
SGF.B.createDebugValueAddr(loc, argrv.getValue(),
258-
SILDebugVariable(vd->isLet(), ArgNo));
259-
else
260-
SGF.B.createDebugValue(loc, argrv.getValue(),
261-
SILDebugVariable(vd->isLet(), ArgNo));
256+
SILValue value = argrv.getValue();
257+
SILDebugVariable varinfo(vd->isLet(), ArgNo);
258+
if (!argrv.getType().isAddress()) {
259+
SGF.B.createDebugValue(loc, value, varinfo);
260+
} else {
261+
if (auto AllocStack = dyn_cast<AllocStackInst>(value))
262+
AllocStack->setArgNo(ArgNo);
263+
else
264+
SGF.B.createDebugValueAddr(loc, value, varinfo);
265+
}
262266
}
263267

264268
void emitParam(ParamDecl *PD) {

test/DebugInfo/alloc_stack_arg.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
public func snd<T, U>(_ t : (T, U)) -> U {
3+
let (_, y) = t
4+
return y
5+
}
6+
7+
// Test that the alloc_stack's argument number is preserved.
8+
// CHECK-NOT: !DILocalVariable(name: "t"
9+
// CHECK: !DILocalVariable(name: "t", arg: 1
10+
// CHECK-NOT: !DILocalVariable(name: "t"

test/SILGen/let_decls.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,11 @@ func testDebugValue(_ a : Int, b : SimpleProtocol) -> Int {
344344
// CHECK-LABEL: sil hidden @{{.*}}testAddressOnlyTupleArgument
345345
func testAddressOnlyTupleArgument(_ bounds: (start: SimpleProtocol, pastEnd: Int)) {
346346
// CHECK: bb0(%0 : @trivial $*SimpleProtocol, %1 : @trivial $Int):
347-
// CHECK-NEXT: %2 = alloc_stack $(start: SimpleProtocol, pastEnd: Int), let, name "bounds"
347+
// CHECK-NEXT: %2 = alloc_stack $(start: SimpleProtocol, pastEnd: Int), let, name "bounds", argno 1
348348
// CHECK-NEXT: %3 = tuple_element_addr %2 : $*(start: SimpleProtocol, pastEnd: Int), 0
349349
// CHECK-NEXT: copy_addr %0 to [initialization] %3 : $*SimpleProtocol
350350
// CHECK-NEXT: %5 = tuple_element_addr %2 : $*(start: SimpleProtocol, pastEnd: Int), 1
351351
// CHECK-NEXT: store %1 to [trivial] %5 : $*Int
352-
// CHECK-NEXT: debug_value_addr %2
353352
// CHECK-NEXT: destroy_addr %2 : $*(start: SimpleProtocol, pastEnd: Int)
354353
// CHECK-NEXT: dealloc_stack %2 : $*(start: SimpleProtocol, pastEnd: Int)
355354
}

0 commit comments

Comments
 (0)