[flang-commits] [flang] [flang] Pad Hollerith actual arguments (PR #139782)
via flang-commits
flang-commits at lists.llvm.org
Tue May 13 12:41:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/139782.diff
2 Files Affected:
- (modified) flang/lib/Semantics/expression.cpp (+13)
- (added) flang/test/Semantics/pad-hollerith-arg.f (+5)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/139782
More information about the flang-commits
mailing list