[flang-commits] [flang] [flang] Pad Hollerith actual arguments (PR #139782)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue May 13 12:41:08 PDT 2025


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/139782

For more compatible legacy behavior on old tests, extend Hollerith actual arguments on the right with trailing blanks out to a multiple of 8 bytes.  Fixes Fujitsu test 0343_0069.

>From 8f3a00e948510a6e4b130dc40828e5bc0f5a5e8d Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 13 May 2025 12:37:34 -0700
Subject: [PATCH] [flang] Pad Hollerith actual arguments

For more compatible legacy behavior on old tests, extend
Hollerith actual arguments on the right with trailing blanks
out to a multiple of 8 bytes.  Fixes Fujitsu test 0343_0069.
---
 flang/lib/Semantics/expression.cpp       | 13 +++++++++++++
 flang/test/Semantics/pad-hollerith-arg.f |  5 +++++
 2 files changed, 18 insertions(+)
 create mode 100644 flang/test/Semantics/pad-hollerith-arg.f

diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index c35492097cfbc..b3ad608ee6744 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -4904,6 +4904,19 @@ std::optional<ActualArgument> ArgumentAnalyzer::AnalyzeExpr(
         "TYPE(*) dummy argument may only be used as an actual argument"_err_en_US);
   } else if (MaybeExpr argExpr{AnalyzeExprOrWholeAssumedSizeArray(expr)}) {
     if (isProcedureCall_ || !IsProcedureDesignator(*argExpr)) {
+      // Pad Hollerith actual argument with spaces up to a multiple of 8
+      // bytes, in case the data are interpreted as double precision
+      // (or a smaller numeric type) by legacy code.
+      if (auto hollerith{UnwrapExpr<Constant<Ascii>>(*argExpr)};
+          hollerith && hollerith->wasHollerith()) {
+        std::string bytes{hollerith->values()};
+        while ((bytes.size() % 8) != 0) {
+          bytes += ' ';
+        }
+        Constant<Ascii> c{std::move(bytes)};
+        c.set_wasHollerith(true);
+        argExpr = AsGenericExpr(std::move(c));
+      }
       ActualArgument arg{std::move(*argExpr)};
       SetArgSourceLocation(arg, expr.source);
       return std::move(arg);
diff --git a/flang/test/Semantics/pad-hollerith-arg.f b/flang/test/Semantics/pad-hollerith-arg.f
new file mode 100644
index 0000000000000..75678441ea45f
--- /dev/null
+++ b/flang/test/Semantics/pad-hollerith-arg.f
@@ -0,0 +1,5 @@
+! RUN: %flang_fc1 -fdebug-unparse %s | FileCheck %s
+! Ensure that Hollerith actual arguments are blank padded.
+! CHECK: CALL foo("abc     ")
+      call foo(3habc)
+      end



More information about the flang-commits mailing list