Page MenuHomePhabricator

Fix SourceMgrDiagnosticHandler::convertLocToSMLoc for unknown line/column scenerio.
Needs ReviewPublic

Authored by Jing on Tue, May 19, 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.Tue, May 19, 4:53 PM
Herald added a project: Restricted Project. · View Herald Transcript
Jing edited the summary of this revision. (Show Details)Tue, May 19, 5:09 PM
Jing added a reviewer: mehdi_amini.
Jing added a project: Restricted Project.
mehdi_amini added inline comments.Tue, May 19, 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.Tue, May 19, 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.Sat, May 23, 3:32 PM

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

Jing added a comment.Mon, May 25, 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.