[PATCH] D118992: [flang] Add lowering for ASCII character constant
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 4 06:27:32 PST 2022
clementval created this revision.
clementval added reviewers: jeanPerier, kiranchandramohan, PeteSteinfeld, schweitz, svedanayagam.
Herald added a subscriber: mehdi_amini.
Herald added a project: Flang.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
Lower character constant of KIND = 1 with the
`createStringLiteral` helper function.
This patch is part of the upstreaming effort from fir-dev branch.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118992
Files:
flang/lib/Lower/ConvertExpr.cpp
Index: flang/lib/Lower/ConvertExpr.cpp
===================================================================
--- flang/lib/Lower/ConvertExpr.cpp
+++ flang/lib/Lower/ConvertExpr.cpp
@@ -246,6 +246,15 @@
}
}
+ /// 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));
+ 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>>
@@ -256,7 +265,9 @@
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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118992.405945.patch
Type: text/x-patch
Size: 1236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220204/8c9acf7b/attachment.bin>
More information about the llvm-commits
mailing list