Skip to content

Commit c87bd7f

Browse files
[DebugInfo] Use Stmt EndLoc if SILLocation passed in is the Stmt EndLoc.
When creating an ExtendedASTNodeLoc from a SILLocation, if the SILLocation passed in belongs to a swift::Stmt, we only ever use the Stmt's StartLoc for the SourceLocation. If the SILLocation passed in, has a SourceLocation that matches the EndLoc of the Stmt, we should correctly set the primary ASTNodeTy PointerUnion's integer to 1, to denote that the SourceLocation dervied from the Stmt points to the EndLoc.
1 parent 351d66a commit c87bd7f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/SIL/IR/SILLocation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,14 @@ RegularLocation::getDebugOnlyExtendedASTNodeLoc(SILLocation L,
290290
return new (Module) ExtendedASTNodeLoc(Empty, {D, 0});
291291
if (auto E = L.getAsASTNode<Expr>())
292292
return new (Module) ExtendedASTNodeLoc(Empty, {E, 0});
293-
if (auto S = L.getAsASTNode<Stmt>())
293+
if (auto S = L.getAsASTNode<Stmt>()) {
294+
// If the source locatuon of the SILLocation passed in matches the EndLoc of
295+
// the Stmt, set the primary ASTNodeTy integer to 1, therefore
296+
// SILLocation::getSourceLoc returns the EndLoc when queried.
297+
if (L.getSourceLocForDebugging() == S->getEndLoc())
298+
Empty.setInt(1);
294299
return new (Module) ExtendedASTNodeLoc(Empty, {S, 0});
300+
}
295301
auto P = L.getAsASTNode<Pattern>();
296302
return new (Module) ExtendedASTNodeLoc(Empty, {P, 0});
297303
}

test/DebugInfo/hop_to_executor.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swiftc_driver %s -c -g -Onone -o - -Xllvm -sil-print-debuginfo -emit-sil -parse-as-library -module-name m | %FileCheck %s
2+
3+
// This test ensures that the hop_to_executor source location matches the end of the do block
4+
5+
// CHECK: %35 = function_ref @swift_asyncLet_finish : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc {{.*}}:19:3, scope 8
6+
// CHECK-NEXT: %36 = apply %35(%10, %5) : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc{{.*}}:19:3
7+
// CHECK-NEXT: hop_to_executor %0, loc * {{.*}}:19:3, scope 8
8+
9+
10+
func getTimestamp(x: Int) async -> Int {
11+
return 40 + x
12+
}
13+
func work() {}
14+
func foo() async {
15+
do {
16+
work()
17+
async let timestamp2 = getTimestamp(x:2)
18+
print(await timestamp2)
19+
}
20+
work()
21+
}
22+
@main enum entry {
23+
static func main() async {
24+
await foo()
25+
}
26+
}

0 commit comments

Comments
 (0)