From 270a336ff46204acf887def32c92ad695f767471 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 19 Mar 2021 05:32:19 +0000 Subject: [PATCH] [mlir] Fix Python bindings tests failure in Debug mode after D98474 Add extra `type.isa()` check to `FloatAttr::get(Type, double)` method. Otherwise it tries to call `type.cast()`, which fails with assertion in Debug mode. The `!type.isa()` case just redirercts the call to `FloatAttr::get(Type, APFloat)`, which will perform the actual check and emit appropriate error. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D98764 --- mlir/include/mlir/IR/BuiltinAttributes.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td index 433c33521a7a..45214535b1f8 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -406,7 +406,7 @@ def Builtin_FloatAttr : Builtin_Attr<"Float"> { return $_get(type.getContext(), type, value); }]>, AttrBuilderWithInferredContext<(ins "Type":$type, "double":$value), [{ - if (type.isF64()) + if (type.isF64() || !type.isa()) return $_get(type.getContext(), type, APFloat(value)); // This handles, e.g., F16 because there is no APFloat constructor for it.