Skip to content

Commit 07d5895

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 07d5895

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,9 @@ llvm::Value *IRGenFunction::getDynamicSelfMetadata() {
18451845
cast<llvm::Instruction>(SelfValue)))
18461846
: CurFn->getEntryBlock().begin();
18471847
Builder.SetInsertPoint(&CurFn->getEntryBlock(), insertPt);
1848+
// Do not inherit the debug location of this insertion point, it could be
1849+
// anything (e.g. the location of a dbg.declare).
1850+
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
18481851

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

0 commit comments

Comments
 (0)