[flang-commits] [flang] [flang] Support fir.boxchar in getTypeAsString (PR #70997)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Wed Nov 1 15:41:46 PDT 2023
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/70997
>From 15b2abc4904094a79f6dedd3f6d42ea3074d26a7 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 1 Nov 2023 15:21:20 -0700
Subject: [PATCH 1/2] [flang] Support fir.boxchar in getTypeAsString
---
flang/lib/Optimizer/Dialect/FIRType.cpp | 7 ++++++-
flang/unittests/Optimizer/FIRTypesTest.cpp | 2 ++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 323b589cc7f2eb1..09c2a7875843f2f 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -545,7 +545,9 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
break;
} else if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(ty)) {
name << 'c' << kindMap.getCharacterBitsize(charTy.getFKind());
- if (charTy.getLen() != fir::CharacterType::singleton())
+ if (charTy.getLen() == fir::CharacterType::unknownLen())
+ name << "x?";
+ else if (charTy.getLen() != fir::CharacterType::singleton())
name << "x" << charTy.getLen();
break;
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(ty)) {
@@ -574,6 +576,9 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(ty)) {
name << "box_";
ty = boxTy.getEleTy();
+ } else if (auto boxcharTy = mlir::dyn_cast_or_null<fir::BoxCharType>(ty)) {
+ name << "boxchar_";
+ ty = boxcharTy.getEleTy();
} else if (auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(ty)) {
name << "rec_" << recTy.getName();
break;
diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp
index b66c1ff441badeb..82846fff5847651 100644
--- a/flang/unittests/Optimizer/FIRTypesTest.cpp
+++ b/flang/unittests/Optimizer/FIRTypesTest.cpp
@@ -313,4 +313,6 @@ TEST_F(FIRTypesTest, getTypeAsString) {
fir::getTypeAsString(
fir::LLVMPointerType::get(mlir::IntegerType::get(&context, 32)),
*kindMap));
+ EXPECT_EQ("boxchar_c8x?",
+ fir::getTypeAsString(fir::BoxCharType::get(&context, 1), *kindMap));
}
>From cf0bae76f60cb1e8d0b6b42793b3270cf4b90f39 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 1 Nov 2023 15:41:33 -0700
Subject: [PATCH 2/2] Avoid special character
---
flang/lib/Optimizer/Dialect/FIRType.cpp | 2 +-
flang/unittests/Optimizer/FIRTypesTest.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 09c2a7875843f2f..efaead599bee169 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -546,7 +546,7 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
} else if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(ty)) {
name << 'c' << kindMap.getCharacterBitsize(charTy.getFKind());
if (charTy.getLen() == fir::CharacterType::unknownLen())
- name << "x?";
+ name << "xU";
else if (charTy.getLen() != fir::CharacterType::singleton())
name << "x" << charTy.getLen();
break;
diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp
index 82846fff5847651..238aa6939d5df35 100644
--- a/flang/unittests/Optimizer/FIRTypesTest.cpp
+++ b/flang/unittests/Optimizer/FIRTypesTest.cpp
@@ -313,6 +313,6 @@ TEST_F(FIRTypesTest, getTypeAsString) {
fir::getTypeAsString(
fir::LLVMPointerType::get(mlir::IntegerType::get(&context, 32)),
*kindMap));
- EXPECT_EQ("boxchar_c8x?",
+ EXPECT_EQ("boxchar_c8xU",
fir::getTypeAsString(fir::BoxCharType::get(&context, 1), *kindMap));
}
More information about the flang-commits
mailing list