@@ -33,24 +33,26 @@ struct ComplexTest : public testing::Test {
33
33
helper = std::make_unique<fir::factory::Complex>(*firBuilder, loc);
34
34
35
35
// Init commonly used types
36
- realTy = mlir::FloatType::getF32 (&context);
37
- cType1 = fir::ComplexType::get (&context, 4 );
36
+ realTy1 = mlir::FloatType::getF32 (&context);
37
+ complexTy1 = fir::ComplexType::get (&context, 4 );
38
+ integerTy1 = mlir::IntegerType::get (&context, 32 );
38
39
39
- // Init commonly used numbers
40
- rOne = firBuilder->createRealConstant (loc, realTy , 1u );
41
- rTwo = firBuilder->createRealConstant (loc, realTy , 2u );
42
- rThree = firBuilder->createRealConstant (loc, realTy , 3u );
43
- rFour = firBuilder->createRealConstant (loc, realTy , 4u );
40
+ // Create commonly used reals
41
+ rOne = firBuilder->createRealConstant (loc, realTy1 , 1u );
42
+ rTwo = firBuilder->createRealConstant (loc, realTy1 , 2u );
43
+ rThree = firBuilder->createRealConstant (loc, realTy1 , 3u );
44
+ rFour = firBuilder->createRealConstant (loc, realTy1 , 4u );
44
45
}
45
46
46
47
mlir::MLIRContext context;
47
48
std::unique_ptr<fir::KindMapping> kindMap;
48
49
std::unique_ptr<fir::FirOpBuilder> firBuilder;
49
50
std::unique_ptr<fir::factory::Complex> helper;
50
51
51
- // Commonly used real/complex types
52
- mlir::FloatType realTy;
53
- fir::ComplexType cType1;
52
+ // Commonly used real/complex/integer types
53
+ mlir::FloatType realTy1;
54
+ fir::ComplexType complexTy1;
55
+ mlir::IntegerType integerTy1;
54
56
55
57
// Commonly used real numbers
56
58
mlir::Value rOne;
@@ -60,7 +62,7 @@ struct ComplexTest : public testing::Test {
60
62
};
61
63
62
64
TEST_F (ComplexTest, verifyTypes) {
63
- mlir::Value cVal1 = helper->createComplex (cType1 , rOne, rTwo);
65
+ mlir::Value cVal1 = helper->createComplex (complexTy1 , rOne, rTwo);
64
66
mlir::Value cVal2 = helper->createComplex (4 , rOne, rTwo);
65
67
EXPECT_TRUE (fir::isa_complex (cVal1.getType ()));
66
68
EXPECT_TRUE (fir::isa_complex (cVal2.getType ()));
@@ -71,10 +73,10 @@ TEST_F(ComplexTest, verifyTypes) {
71
73
mlir::Value imag1 = helper->extractComplexPart (cVal1, /* isImagPart=*/ true );
72
74
mlir::Value real2 = helper->extractComplexPart (cVal2, /* isImagPart=*/ false );
73
75
mlir::Value imag2 = helper->extractComplexPart (cVal2, /* isImagPart=*/ true );
74
- EXPECT_EQ (realTy , real1.getType ());
75
- EXPECT_EQ (realTy , imag1.getType ());
76
- EXPECT_EQ (realTy , real2.getType ());
77
- EXPECT_EQ (realTy , imag2.getType ());
76
+ EXPECT_EQ (realTy1 , real1.getType ());
77
+ EXPECT_EQ (realTy1 , imag1.getType ());
78
+ EXPECT_EQ (realTy1 , real2.getType ());
79
+ EXPECT_EQ (realTy1 , imag2.getType ());
78
80
79
81
mlir::Value cVal3 =
80
82
helper->insertComplexPart (cVal1, rThree, /* isImagPart=*/ false );
@@ -83,3 +85,16 @@ TEST_F(ComplexTest, verifyTypes) {
83
85
EXPECT_TRUE (fir::isa_complex (cVal4.getType ()));
84
86
EXPECT_TRUE (fir::isa_real (helper->getComplexPartType (cVal4)));
85
87
}
88
+
89
+ TEST_F (ComplexTest, verifyConvertWithSemantics) {
90
+ auto loc = firBuilder->getUnknownLoc ();
91
+ rOne = firBuilder->createRealConstant (loc, realTy1, 1u );
92
+ // Convert real to complex
93
+ mlir::Value v1 = firBuilder->convertWithSemantics (loc, complexTy1, rOne);
94
+ EXPECT_TRUE (fir::isa_complex (v1.getType ()));
95
+
96
+ // Convert complex to integer
97
+ mlir::Value v2 = firBuilder->convertWithSemantics (loc, integerTy1, v1);
98
+ EXPECT_TRUE (v2.getType ().isa <mlir::IntegerType>());
99
+ EXPECT_TRUE (mlir::dyn_cast<fir::ConvertOp>(v2.getDefiningOp ()));
100
+ }
0 commit comments