Skip to content

Commit 8f3100a

Browse files
committed
[IRGen] Correctly decode SILLocation w/ FilenameAndLocation storage
IRGen tried to decode various types of `SILLocation` into `FilenameAndLocation` object. But it couldn't handle the case where `SILLocation` already uses `FilenameAndLocationKind` storage kind. This patch fixes this issue. Resolves SR-14856
1 parent 340c855 commit 8f3100a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
288288
FilenameAndLocation getStartLocation(Optional<SILLocation> OptLoc) {
289289
if (!OptLoc)
290290
return {};
291+
if (OptLoc->isFilenameAndLocation())
292+
return sanitizeCodeViewFilenameAndLocation(*OptLoc->getFilenameAndLocation());
291293
return decodeSourceLoc(OptLoc->getStartSourceLoc());
292294
}
293295

test/IRGen/debug_scope.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swiftc_driver -g -emit-ir %s | %FileCheck %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
// SR-14856: IRGen couldn't handle `SILLocation` with `FilenameAndLocationKind`
8+
// storage kind.
9+
10+
sil_scope 2 { loc "the_file.swift":2:6 parent @foo : $@convention(thin) () -> () }
11+
sil_scope 3 { loc "the_file.swift":3:5 parent 2 }
12+
13+
// It shouldn't crash
14+
// CHECK: @foo
15+
// CHECK-SAME: !dbg ![[FUNC_DI:[0-9]+]]
16+
sil hidden @foo : $@convention(thin) () -> () {
17+
bb0:
18+
%2 = integer_literal $Builtin.Int64, 17, loc "the_file.swift":3:12, scope 3
19+
%3 = tuple ()
20+
return %3 : $()
21+
}
22+
23+
// Debug info should be correctly generated
24+
// CHECK: distinct !DILexicalBlock(scope: ![[FUNC_DI]]
25+
// CHECK-SAME: file: ![[FILE_DI:[0-9]+]]
26+
// CHECK-SAME: line: 3, column: 5
27+
// CHECK: ![[FILE_DI]] = !DIFile(filename: "the_file.swift"

0 commit comments

Comments
 (0)