Skip to content

Commit f1abf5e

Browse files
committed
Swift: Compensate for backwards going locations
1 parent 8f12b40 commit f1abf5e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

swift/extractor/infra/SwiftLocationExtractor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ void SwiftLocationExtractor::attachLocationImpl(const swift::SourceManager& sour
2929
entry.file = fetchFileLabel(file);
3030
std::tie(entry.start_line, entry.start_column) =
3131
sourceManager.getLineAndColumnInBuffer(range.Start);
32-
std::tie(entry.end_line, entry.end_column) = sourceManager.getLineAndColumnInBuffer(range.End);
32+
if (sourceManager.getLineAndColumnInBuffer(range.End) >=
33+
sourceManager.getLineAndColumnInBuffer(range.Start)) {
34+
std::tie(entry.end_line, entry.end_column) = sourceManager.getLineAndColumnInBuffer(range.End);
35+
} else {
36+
// the compiler may generate source ranges that go backwards
37+
entry.end_line = entry.start_line;
38+
entry.end_column = entry.start_column;
39+
}
3340
SwiftMangledName locName{"loc", entry.file, ':', entry.start_line, ':', entry.start_column,
3441
':', entry.end_line, ':', entry.end_column};
3542
entry.id = trap.createTypedLabel<DbLocationTag>(locName);

0 commit comments

Comments
 (0)