[PATCH] D118992: [flang] Add lowering for ASCII character constant

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 7 02:16:43 PST 2022


clementval updated this revision to Diff 406365.
clementval added a comment.

Rebase + address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118992/new/

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
@@ -292,6 +292,16 @@
     }
   }
 
+  /// 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 @@
         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.406365.patch
Type: text/x-patch
Size: 1289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220207/1d3ff60f/attachment.bin>


More information about the llvm-commits mailing list