[Mlir-commits] [mlir] eddf4dc - Fix SourceMgrDiagnosticHandler::convertLocToSMLoc for unknown line/column scenerio.
River Riddle
llvmlistbot at llvm.org
Mon Jun 15 16:16:09 PDT 2020
Author: Jing Pu
Date: 2020-06-15T16:15:12-07:00
New Revision: eddf4dc869dbdedb81ab6f718b33d6db9f7cdaa1
URL: https://github.com/llvm/llvm-project/commit/eddf4dc869dbdedb81ab6f718b33d6db9f7cdaa1
DIFF: https://github.com/llvm/llvm-project/commit/eddf4dc869dbdedb81ab6f718b33d6db9f7cdaa1.diff
LOG: Fix SourceMgrDiagnosticHandler::convertLocToSMLoc for unknown line/column scenerio.
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
Differential Revision: https://reviews.llvm.org/D80258
Added:
Modified:
mlir/lib/IR/Diagnostics.cpp
Removed:
################################################################################
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index ec2ca9363408..34908c61639f 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -509,6 +509,11 @@ SourceMgrDiagnosticHandler::getBufferForFile(StringRef filename) {
/// Get a memory buffer for the given file, or the main file of the source
/// manager if one doesn't exist. This always returns non-null.
llvm::SMLoc SourceMgrDiagnosticHandler::convertLocToSMLoc(FileLineColLoc loc) {
+ // The column and line may be zero to represent unknown column and/or unknown
+ /// line/column information.
+ if (loc.getLine() == 0 || loc.getColumn() == 0)
+ return llvm::SMLoc();
+
unsigned bufferId = impl->getSourceMgrBufferIDForFile(mgr, loc.getFilename());
if (!bufferId)
return llvm::SMLoc();
More information about the Mlir-commits
mailing list