Skip to content

Commit 56d8a8d

Browse files
committed
When generating debug info for AllocStackInst, make sure to describe the alloca.
This way an llvm.dbg.declare instrinsic is used, which is valid for the entire lifetime of the alloca. rdar://problem/36663932
1 parent de617e7 commit 56d8a8d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
38853885
RealType, type, false);
38863886
bool IsAnonymous = false;
38873887
StringRef Name = getVarName(i, IsAnonymous);
3888+
// Describe the underlying alloca. This way an llvm.dbg.declare instrinsic
3889+
// is used, which is valid for the entire lifetime of the alloca.
3890+
if (auto *BitCast = dyn_cast<llvm::BitCastInst>(addr))
3891+
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(BitCast->getOperand(0)))
3892+
addr = Alloca;
38883893
if (auto DS = i->getDebugScope())
38893894
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, Decl, Name,
38903895
i->getVarInfo().ArgNo);

test/DebugInfo/generic_enum_closure.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ struct CErrorOr<T>
88
// CHECK: define hidden {{.*}}void @"$S20generic_enum_closure8CErrorOrV1xACyxGAA14__CurrentErrnoV_tcfC"
99
// CHECK-NOT: define
1010
// This is a SIL-level debug_value_addr instruction.
11-
// CHECK: call void @llvm.dbg.value({{.*}}, metadata ![[SELF:.*]], metadata !DIExpression())
11+
// CHECK: call void @llvm.dbg.declare
12+
// CHECK: call void @llvm.dbg.declare({{.*}}, metadata ![[SELF:.*]], metadata !DIExpression())
1213
// CHECK: ![[T1:.*]] = !DICompositeType({{.*}}, identifier: "$S20generic_enum_closure8CErrorOrVyACQq_GD")
1314
// CHECK: ![[SELF]] = !DILocalVariable(name: "self", scope: {{.*}}, type: ![[T1]])
1415
value = .none

test/DebugInfo/resilience.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -g -emit-module -enable-resilience \
3+
// RUN: -emit-module-path=%t/resilient_struct.swiftmodule \
4+
// RUN: -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
5+
// RUN: %target-swift-frontend -g -I %t -emit-ir -enable-resilience %s \
6+
// RUN: | %FileCheck %s
7+
import resilient_struct
8+
9+
func use<T>(_ t: T) {}
10+
11+
public func f() {
12+
let s1 = Size(w: 1, h: 2)
13+
use(s1)
14+
// CHECK: %[[USE_BUFFER:.*]] = alloca i8,
15+
// CHECK: %[[S1:.*]] = alloca i8,
16+
// CHECK: call void @llvm.dbg.declare(metadata i8* %[[S1]],
17+
// CHECK-SAME: metadata ![[V1:[0-9]+]],
18+
// CHECK-SAME: metadata !DIExpression())
19+
// CHECK: ![[V1]] = !DILocalVariable(name: "s1", {{.*}}type: ![[TY:[0-9]+]])
20+
// CHECK: ![[TY]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size",
21+
// FIXME-NOT: size:
22+
// CHECK: =
23+
}

0 commit comments

Comments
 (0)