diff options
| author | Jacques Pienaar <jpienaar@google.com> | 2019-09-23 15:51:11 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-09-23 15:51:42 -0700 |
| commit | 4a862fbd6337bb926e7a88ed4749b726e1a09ed9 (patch) | |
| tree | 2056f519c574c98bf91fc8abcd205e4cf222fb11 /mlir/lib/Parser | |
| parent | 98d1d3fc437f5d2b9b3dc99ab79ee734c8127072 (diff) | |
| download | bcm5719-llvm-4a862fbd6337bb926e7a88ed4749b726e1a09ed9.tar.gz bcm5719-llvm-4a862fbd6337bb926e7a88ed4749b726e1a09ed9.zip | |
Use constant's location for reporting errors in parsing of hex constant
Before this the line following the error would be reported in some cases.
PiperOrigin-RevId: 270778722
Diffstat (limited to 'mlir/lib/Parser')
| -rw-r--r-- | mlir/lib/Parser/Parser.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index cb0d329e343..9fd2176d0c6 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1191,6 +1191,7 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { // Remember if the literal is hexadecimal. StringRef spelling = getToken().getSpelling(); + auto loc = state.curToken.getLoc(); bool isHex = spelling.size() > 1 && spelling[1] == 'x'; consumeToken(Token::integer); @@ -1202,16 +1203,19 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { return nullptr; } - // Hexadecimal representation of float literals is not supported for bfloat16. - // When supported, the literal should be unsigned. - auto floatType = type.dyn_cast<FloatType>(); - if (floatType && !type.isBF16()) { - if (isNegative) { - emitError("hexadecimal float literal should not have a leading minus"); - return nullptr; - } + if (auto floatType = type.dyn_cast<FloatType>()) { + // TODO(zinenko): Update once hex format for bfloat16 is supported. + if (type.isBF16()) + return emitError(loc, + "hexadecimal float literal not supported for bfloat16"), + nullptr; + if (isNegative) + return emitError( + loc, + "hexadecimal float literal should not have a leading minus"), + nullptr; if (!isHex) { - emitError("unexpected decimal integer literal for a float attribute") + emitError(loc, "unexpected decimal integer literal for a float attribute") .attachNote() << "add a trailing dot to make the literal a float"; return nullptr; @@ -1222,17 +1226,20 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { } if (!type.isIntOrIndex()) - return (emitError("integer literal not valid for specified type"), nullptr); + return emitError(loc, "integer literal not valid for specified type"), + nullptr; // Parse the integer literal. int width = type.isIndex() ? 64 : type.getIntOrFloatBitWidth(); APInt apInt(width, *val, isNegative); if (apInt != *val) - return (emitError("integer constant out of range for attribute"), nullptr); + return emitError(loc, "integer constant out of range for attribute"), + nullptr; // Otherwise construct an integer attribute. if (isNegative ? (int64_t)-val.getValue() >= 0 : (int64_t)val.getValue() < 0) - return (emitError("integer constant out of range for attribute"), nullptr); + return emitError(loc, "integer constant out of range for attribute"), + nullptr; return builder.getIntegerAttr(type, isNegative ? -apInt : apInt); } |

