Skip to content

Commit 9457616

Browse files
authored
[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.
1 parent faf5d74 commit 9457616

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,6 +4904,19 @@ std::optional<ActualArgument> ArgumentAnalyzer::AnalyzeExpr(
49044904
"TYPE(*) dummy argument may only be used as an actual argument"_err_en_US);
49054905
} else if (MaybeExpr argExpr{AnalyzeExprOrWholeAssumedSizeArray(expr)}) {
49064906
if (isProcedureCall_ || !IsProcedureDesignator(*argExpr)) {
4907+
// Pad Hollerith actual argument with spaces up to a multiple of 8
4908+
// bytes, in case the data are interpreted as double precision
4909+
// (or a smaller numeric type) by legacy code.
4910+
if (auto hollerith{UnwrapExpr<Constant<Ascii>>(*argExpr)};
4911+
hollerith && hollerith->wasHollerith()) {
4912+
std::string bytes{hollerith->values()};
4913+
while ((bytes.size() % 8) != 0) {
4914+
bytes += ' ';
4915+
}
4916+
Constant<Ascii> c{std::move(bytes)};
4917+
c.set_wasHollerith(true);
4918+
argExpr = AsGenericExpr(std::move(c));
4919+
}
49074920
ActualArgument arg{std::move(*argExpr)};
49084921
SetArgSourceLocation(arg, expr.source);
49094922
return std::move(arg);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: %flang_fc1 -fdebug-unparse %s | FileCheck %s
2+
! Ensure that Hollerith actual arguments are blank padded.
3+
! CHECK: CALL foo("abc ")
4+
call foo(3habc)
5+
end

0 commit comments

Comments
 (0)