[flang-commits] [flang] b21b907 - [flang] Handle Hollerith in data statement initialization in big endian (#103451)
via flang-commits
flang-commits at lists.llvm.org
Sat Aug 17 13:53:15 PDT 2024
Author: Kelvin Li
Date: 2024-08-17T16:53:11-04:00
New Revision: b21b907aeb36a4ce6b403944e9c440a3bba5c3e0
URL: https://github.com/llvm/llvm-project/commit/b21b907aeb36a4ce6b403944e9c440a3bba5c3e0
DIFF: https://github.com/llvm/llvm-project/commit/b21b907aeb36a4ce6b403944e9c440a3bba5c3e0.diff
LOG: [flang] Handle Hollerith in data statement initialization in big endian (#103451)
Update to read the Hollerith literal in reverse order for big endian
environment.
Added:
Modified:
flang/lib/Evaluate/tools.cpp
flang/test/Semantics/data08.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 4d78f814f8ef2c..6b3db619c1e2f1 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1300,12 +1300,12 @@ std::optional<Expr<SomeType>> HollerithToBOZ(FoldingContext &context,
const Expr<SomeType> &expr, const DynamicType &type) {
if (std::optional<std::string> chValue{GetScalarConstantValue<Ascii>(expr)}) {
// Pad on the right with spaces when short, truncate the right if long.
- // TODO: big-endian targets
auto bytes{static_cast<std::size_t>(
ToInt64(type.MeasureSizeInBytes(context, false)).value())};
BOZLiteralConstant bits{0};
for (std::size_t j{0}; j < bytes; ++j) {
- char ch{j >= chValue->size() ? ' ' : chValue->at(j)};
+ auto idx{isHostLittleEndian ? j : bytes - j - 1};
+ char ch{idx >= chValue->size() ? ' ' : chValue->at(idx)};
BOZLiteralConstant chBOZ{static_cast<unsigned char>(ch)};
bits = bits.IOR(chBOZ.SHIFTL(8 * j));
}
diff --git a/flang/test/Semantics/data08.f90 b/flang/test/Semantics/data08.f90
index 7bd70637aabda7..7e12a71d117728 100644
--- a/flang/test/Semantics/data08.f90
+++ b/flang/test/Semantics/data08.f90
@@ -1,12 +1,19 @@
-! RUN: %flang_fc1 -fdebug-dump-symbols -pedantic %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fdebug-dump-symbols -pedantic %s 2>&1 | FileCheck %s \
+! RUN: --check-prefixes=%if system-aix %{"CHECK","BE"%} \
+! RUN: %else %{"CHECK","LE"%}
+
! CHECK: DATA statement value initializes 'jx' of type 'INTEGER(4)' with CHARACTER
! CHECK: DATA statement value initializes 'jy' of type 'INTEGER(4)' with CHARACTER
! CHECK: DATA statement value initializes 'jz' of type 'INTEGER(4)' with CHARACTER
! CHECK: DATA statement value initializes 'kx' of type 'INTEGER(8)' with CHARACTER
-! CHECK: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1684234849_4
-! CHECK: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:543384161_4
-! CHECK: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1684234849_4
-! CHECK: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7523094288207667809_8
+! LE: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1684234849_4
+! BE: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1633837924_4
+! LE: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:543384161_4
+! BE: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:1633837856_4
+! LE: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1684234849_4
+! BE: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1633837924_4
+! LE: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7523094288207667809_8
+! BE: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7017280452245743464_8
integer :: jx, jy, jz
integer(8) :: kx
More information about the flang-commits
mailing list