This is an archive of the discontinued LLVM Phabricator instance.

Fix SourceMgrDiagnosticHandler::convertLocToSMLoc for unknown line/column scenerio.
ClosedPublic

Authored by Jing on May 19 2020, 4:53 PM.

Details

Summary

FileLineColLoc allows the column and line to be zero to represent unknown column and/or unknown line/column information. However, SourceMgr::FindLocForLineAndColumn treats line 0 and col 0 valid and pointing to the first line and col, respectively. To adapt this mismatch in semantics, we explicitly check line/col being zeros in SourceMgrDiagnosticHandler::convertLocToSMLoc

Diff Detail

Event Timeline

Jing created this revision.May 19 2020, 4:53 PM
Herald added a project: Restricted Project. · View Herald Transcript
Jing edited the summary of this revision. (Show Details)May 19 2020, 5:09 PM
Jing added a reviewer: mehdi_amini.
Jing added a project: Restricted Project.
mehdi_amini added inline comments.May 19 2020, 6:37 PM
mlir/lib/IR/Diagnostics.cpp
515

How do we actually identify when the loc is referring really to the beginning of the file? There isn't a way to figure out?

Jing marked an inline comment as done.May 19 2020, 7:28 PM
Jing added inline comments.
mlir/lib/IR/Diagnostics.cpp
515

SourceMgr::FindLocForLineAndColumn assumes the indices are one-based, but treats line 0 specially that also points the first line.

mehdi_amini accepted this revision.May 23 2020, 3:32 PM

Let me know if you need me to land this for you

Jing added a comment.May 25 2020, 10:23 PM

I found there are some internal tests (on diagnostics) that rely on column zero being the first column.
I am not so sure whether we should adopt that behavior and change API (i.e. treating only row zero being an unknown location) or fix the tests.

rriddle accepted this revision.Jun 5 2020, 10:23 AM

I found there are some internal tests (on diagnostics) that rely on column zero being the first column.
I am not so sure whether we should adopt that behavior and change API (i.e. treating only row zero being an unknown location) or fix the tests.

We should just fix the tests. zero line/zero column seems like a good enough indicator that it is the beginning of the file.

This revision is now accepted and ready to land.Jun 5 2020, 10:23 AM
This revision was automatically updated to reflect the committed changes.