Skip to content

Commit b21b907

Browse files
authored
[flang] Handle Hollerith in data statement initialization in big endian (#103451)
Update to read the Hollerith literal in reverse order for big endian environment.
1 parent f620c5b commit b21b907

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

flang/lib/Evaluate/tools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,12 @@ std::optional<Expr<SomeType>> HollerithToBOZ(FoldingContext &context,
13001300
const Expr<SomeType> &expr, const DynamicType &type) {
13011301
if (std::optional<std::string> chValue{GetScalarConstantValue<Ascii>(expr)}) {
13021302
// Pad on the right with spaces when short, truncate the right if long.
1303-
// TODO: big-endian targets
13041303
auto bytes{static_cast<std::size_t>(
13051304
ToInt64(type.MeasureSizeInBytes(context, false)).value())};
13061305
BOZLiteralConstant bits{0};
13071306
for (std::size_t j{0}; j < bytes; ++j) {
1308-
char ch{j >= chValue->size() ? ' ' : chValue->at(j)};
1307+
auto idx{isHostLittleEndian ? j : bytes - j - 1};
1308+
char ch{idx >= chValue->size() ? ' ' : chValue->at(idx)};
13091309
BOZLiteralConstant chBOZ{static_cast<unsigned char>(ch)};
13101310
bits = bits.IOR(chBOZ.SHIFTL(8 * j));
13111311
}

flang/test/Semantics/data08.f90

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
! RUN: %flang_fc1 -fdebug-dump-symbols -pedantic %s 2>&1 | FileCheck %s
1+
! RUN: %flang_fc1 -fdebug-dump-symbols -pedantic %s 2>&1 | FileCheck %s \
2+
! RUN: --check-prefixes=%if system-aix %{"CHECK","BE"%} \
3+
! RUN: %else %{"CHECK","LE"%}
4+
25
! CHECK: DATA statement value initializes 'jx' of type 'INTEGER(4)' with CHARACTER
36
! CHECK: DATA statement value initializes 'jy' of type 'INTEGER(4)' with CHARACTER
47
! CHECK: DATA statement value initializes 'jz' of type 'INTEGER(4)' with CHARACTER
58
! CHECK: DATA statement value initializes 'kx' of type 'INTEGER(8)' with CHARACTER
6-
! CHECK: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1684234849_4
7-
! CHECK: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:543384161_4
8-
! CHECK: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1684234849_4
9-
! CHECK: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7523094288207667809_8
9+
! LE: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1684234849_4
10+
! BE: jx (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:1633837924_4
11+
! LE: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:543384161_4
12+
! BE: jy (InDataStmt) size=4 offset=4: ObjectEntity type: INTEGER(4) init:1633837856_4
13+
! LE: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1684234849_4
14+
! BE: jz (InDataStmt) size=4 offset=8: ObjectEntity type: INTEGER(4) init:1633837924_4
15+
! LE: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7523094288207667809_8
16+
! BE: kx (InDataStmt) size=8 offset=16: ObjectEntity type: INTEGER(8) init:7017280452245743464_8
1017

1118
integer :: jx, jy, jz
1219
integer(8) :: kx

0 commit comments

Comments
 (0)