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

via flang-commits flang-commits at lists.llvm.org
Thu May 15 11:25:30 PDT 2025


Author: Peter Klausler
Date: 2025-05-15T11:25:26-07:00
New Revision: 9457616527b50590e9c9d5e91723b35b26e447cd

URL: https://github.com/llvm/llvm-project/commit/9457616527b50590e9c9d5e91723b35b26e447cd
DIFF: https://github.com/llvm/llvm-project/commit/9457616527b50590e9c9d5e91723b35b26e447cd.diff

LOG: [flang] Pad Hollerith actual arguments (#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.

Added: 
    flang/test/Semantics/pad-hollerith-arg.f

Modified: 
    flang/lib/Semantics/expression.cpp

Removed: 
    


################################################################################
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