[flang-commits] [flang] 74751f4 - [flang] Add lowering for ASCII character constant
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Feb 7 03:17:47 PST 2022
Author: Valentin Clement
Date: 2022-02-07T12:17:41+01:00
New Revision: 74751f4b0c312592494c6cc9922bea1ec71372a8
URL: https://github.com/llvm/llvm-project/commit/74751f4b0c312592494c6cc9922bea1ec71372a8
DIFF: https://github.com/llvm/llvm-project/commit/74751f4b0c312592494c6cc9922bea1ec71372a8.diff
LOG: [flang] Add lowering for ASCII character constant
Lower character constant of KIND = 1 with the
`createStringLiteral` helper function.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: kiranchandramohan, schweitz
Differential Revision: https://reviews.llvm.org/D118992
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 2f159fe0f3fd..f97e4409aae9 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -292,6 +292,16 @@ class ScalarExprLowering {
}
}
+ /// Convert a ascii scalar literal CHARACTER to IR. (specialization)
+ ExtValue
+ genAsciiScalarLit(const Fortran::evaluate::Scalar<Fortran::evaluate::Type<
+ Fortran::common::TypeCategory::Character, 1>> &value,
+ int64_t len) {
+ assert(value.size() == static_cast<std::uint64_t>(len) &&
+ "value.size() doesn't match with len");
+ return fir::factory::createStringLiteral(builder, getLoc(), value);
+ }
+
template <Fortran::common::TypeCategory TC, int KIND>
ExtValue
genval(const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>>
@@ -302,7 +312,9 @@ class ScalarExprLowering {
opt = con.GetScalarValue();
assert(opt.has_value() && "constant has no value");
if constexpr (TC == Fortran::common::TypeCategory::Character) {
- TODO(getLoc(), "genval char constant");
+ if constexpr (KIND == 1)
+ return genAsciiScalarLit(opt.value(), con.LEN());
+ TODO(getLoc(), "genval for Character with KIND != 1");
} else {
return genScalarLit<TC, KIND>(opt.value());
}
More information about the flang-commits
mailing list