Skip to content

Commit 81b5866

Browse files
[DebugInfo] Fix dynamic self debug loc
The instructions related to producing DynamicSelf metadata are always placed at the start of the function. This creates an issue: which debug location should be used in order to preserve a sane line table? The current implementation just uses w/e debug location is present in the new insertion point, which could, for example, be a debug_declare whose location is not suitable for these purposes. This patch addresses the issue by removing the debug location of instructions associated with producing DynamicSelfMetadata. rdar://120408665
1 parent 4d8c842 commit 81b5866

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ llvm::Value *IRGenFunction::getDynamicSelfMetadata() {
18451845
cast<llvm::Instruction>(SelfValue)))
18461846
: CurFn->getEntryBlock().begin();
18471847
Builder.SetInsertPoint(&CurFn->getEntryBlock(), insertPt);
1848+
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
18481849

18491850
switch (SelfKind) {
18501851
case SwiftMetatype:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend %s -emit-irgen -g -o - | %FileCheck %s
2+
3+
func some_func(_: () -> Void) async {}
4+
5+
class Model {
6+
static func SelfFunction() {}
7+
8+
func foo() async -> () {
9+
let somevar = 10
10+
11+
return await some_func {
12+
Self.SelfFunction()
13+
}
14+
}
15+
}
16+
17+
// Check that the load of DynamicSelf in foo does not have any debug information, as
18+
// this is hoisted to the start of the function.
19+
// CHECK: define {{.*}} @"$s19DynamicSelfLocation5ModelC3fooyyYaF"({{.*}}, ptr swiftself %[[Self:.*]])
20+
// CHECK-NEXT: entry:
21+
// CHECK-NEXT: %2 = load ptr, ptr %[[Self]]
22+
// CHECK-NOT: !dbg
23+
// CHECK-NEXT: call void @llvm.dbg.declare

0 commit comments

Comments
 (0)