Skip to content

Commit 3050605

Browse files
committed
✅ Add test case for negative integer conversion
1 parent 888e8db commit 3050605

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mlir/unittests/Dialect/Utils/test_utils.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <llvm/ADT/SmallVector.h>
1818
#include <memory>
1919
#include <mlir/Dialect/Arith/IR/Arith.h>
20-
#include <mlir/Dialect/Func/IR/FuncOps.h>
2120
#include <mlir/IR/Builders.h>
2221
#include <mlir/IR/MLIRContext.h>
2322
#include <mlir/IR/Operation.h>
@@ -31,7 +30,6 @@ class UtilsTest : public ::testing::Test {
3130
std::unique_ptr<OpBuilder> builder;
3231

3332
void SetUp() override {
34-
context.loadDialect<func::FuncDialect>();
3533
context.loadDialect<arith::ArithDialect>();
3634

3735
builder = std::make_unique<OpBuilder>(&context);
@@ -59,7 +57,7 @@ TEST_F(UtilsTest, valueToDouble) {
5957
EXPECT_DOUBLE_EQ(stdValue.value(), expectedValue);
6058
}
6159

62-
TEST_F(UtilsTest, valueToDoubleCastFromIntegerType) {
60+
TEST_F(UtilsTest, valueToDoubleCastFromInteger) {
6361
constexpr int expectedValue = 42;
6462
auto op = builder->create<arith::ConstantOp>(
6563
builder->getUnknownLoc(), builder->getI32IntegerAttr(expectedValue));
@@ -71,6 +69,18 @@ TEST_F(UtilsTest, valueToDoubleCastFromIntegerType) {
7169
EXPECT_DOUBLE_EQ(stdValue.value(), expectedValue);
7270
}
7371

72+
TEST_F(UtilsTest, valueToDoubleCastFromNegativeInteger) {
73+
constexpr int expectedValue = -123;
74+
auto op = builder->create<arith::ConstantOp>(
75+
builder->getUnknownLoc(), builder->getSI32IntegerAttr(expectedValue));
76+
ASSERT_TRUE(op);
77+
78+
auto value = op.getResult();
79+
auto stdValue = utils::valueToDouble(value);
80+
ASSERT_TRUE(stdValue.has_value());
81+
EXPECT_DOUBLE_EQ(stdValue.value(), expectedValue);
82+
}
83+
7484
TEST_F(UtilsTest, valueToDoubleCastFromMaxUnsignedInteger) {
7585
constexpr auto expectedValue = std::numeric_limits<uint64_t>::max();
7686
constexpr auto bitCount = 64;

0 commit comments

Comments
 (0)