Skip to content

Commit 6dac640

Browse files
authored
Merge pull request #13969 from nkcsgexi/test-line-col
2 parents fd37208 + f633419 commit 6dac640

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,17 @@ int dumpEOFSourceLoc(const char *MainExecutablePath,
252252
auto BufferId = *SF->getBufferID();
253253
SyntaxPrintOptions Opts;
254254
auto Root = SF->getSyntaxRoot();
255-
auto Offset = Root.getEOFToken().getAbsolutePosition(Root).getOffset();
255+
auto AbPos = Root.getEOFToken().getAbsolutePosition(Root);
256+
256257
SourceManager &SourceMgr = SF->getASTContext().SourceMgr;
257258
auto StartLoc = SourceMgr.getLocForBufferStart(BufferId);
258-
auto EndLoc = SourceMgr.getLocForOffset(BufferId, Offset);
259+
auto EndLoc = SourceMgr.getLocForOffset(BufferId, AbPos.getOffset());
260+
261+
// To ensure the correctness of position when translated to line & column pair.
262+
if (SourceMgr.getLineAndColumn(EndLoc) != AbPos.getLineAndColumn()) {
263+
llvm::outs() << "locations should be identical";
264+
return EXIT_FAILURE;
265+
}
259266
llvm::outs() << CharSourceRange(SourceMgr, StartLoc, EndLoc).str();
260267
return 0;
261268
}

0 commit comments

Comments
 (0)