[all-commits] [llvm/llvm-project] 9ef03f: Flang improve fidelity of unformatted I/O endianne...
David Parks via All-commits
all-commits at lists.llvm.org
Wed Sep 30 11:02:11 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 9ef03f1c32b41b7bcdfd02ea97559a6fadeb440b
https://github.com/llvm/llvm-project/commit/9ef03f1c32b41b7bcdfd02ea97559a6fadeb440b
Author: David Parks <djp at david-parks.com>
Date: 2026-09-30 (Wed, 30 Sep 2026)
Changed paths:
A flang-rt/include/flang-rt/runtime/array.h
M flang-rt/include/flang-rt/runtime/environment.h
R flang-rt/lib/runtime/array.h
M flang-rt/lib/runtime/environment.cpp
M flang-rt/lib/runtime/external-unit.cpp
M flang-rt/lib/runtime/io-api-server.cpp
A flang-rt/test/Runtime/fort_convert.f90
M flang/docs/RuntimeEnvironment.md
Log Message:
-----------
Flang improve fidelity of unformatted I/O endianness with FORT_CONVERT_UNIT (#223831)
Add further fidelity to specifying desired endianness of unformatted I/O
file on a per unit basis with the `FORT_CONVERT_UNIT` environment
variable.
To reviewers (friends) I'm not sure about:
1. The correct function prefixing for the FLANG runtime environment.
2. How to test/validate on Windows
3. How to test/validate with CUDA runtime support enabled
Thank you.
https://discourse.llvm.org/t/runtime-unformatted-i-o-conversion-between-big-and-little-endian-formats/91751
Documentation for new environment variable:
## `FORT_CONVERT_UNIT`
Determines the data conversion applied to specific unformatted I/O
units.
```
FORT_CONVERT_UNIT= mode | mode ';' exception | exception ;
mode: 'NATIVE' | 'LITTLE_ENDIAN' | 'BIG_ENDIAN' | 'SWAP';
exception: mode ':' unit_list | unit_list ;
unit_list: unit_spec | unit_list ',' unit_spec ;
unit_spec: integer | integer '-' integer ;
integer: [0-9]+ ;
```
The endianness of unformatted files is determined in the following
order:
1. The host processor's native endianness.
5. The setting of the `-fconvert=<mode>` flang compiler command-line
option.
6. The global setting from the `FORT_CONVERT=mode` or
`FORT_CONVERT_UNIT=mode`
environment variables. Contradictory mode settings between
`FORT_CONVERT` and
`FORT_CONVERT_UNIT` result in `FORT_CONVERT_UNIT` taking priority.
7. The explicit setting of the `CONVERT=` specifier in the `OPEN`
statement for
a particular unit.
8. The exception setting for an individual unit or range of units from
the
`FORT_CONVERT_UNIT` environment variable.
### Examples
* If the `FORT_CONVERT`, `FORT_CONVERT_UNIT`, and `CONVERT=` specifier
in the
`OPEN` statement are all missing, no data conversion is performed for
unformatted I/O; the host processor's native encoding is used.
* If the environment variable `FORT_CONVERT=BIG_ENDIAN` is set and no
`CONVERT=` specifier is present in the `OPEN` statement, input is
assumed to
be big-endian, and output is emitted in big-endian format.
* On a little-endian host, if the environment variable
`FORT_CONVERT=SWAP` is
set and the `CONVERT=LITTLE_ENDIAN` specifier is present in the `OPEN`
statement, the `OPEN` statement takes precedence: input is assumed to be
little-endian, and output is emitted in little-endian format.
* If unit 10 is opened on a little-endian host with the environment
variable
`FORT_CONVERT=SWAP`, `FORT_CONVERT_UNIT=BIG_ENDIAN:10`, and an `OPEN`
statement for unit 10 with the `CONVERT=LITTLE_ENDIAN` specifier, the
`BIG_ENDIAN:10` exception from the `FORT_CONVERT_UNIT` environment
variable
takes precedence: input is assumed to be big-endian, and output is
emitted
in big-endian format.
### Notes
1. `<mode>` values specified with the runtime environment variables
`FORT_CONVERT` or `FORT_CONVERT_UNIT` are case-insensitive.
2. `<mode>` values specified with the flang command-line option
`-fconvert=<mode>` are case-sensitive and include:
`mode: 'native' | 'little-endian' | 'big-endian' | 'swap';`
3. `unit_spec` supports ranges separated by a hyphen. Ranges must denote
positive unit numbers, and the starting unit (LHS) must be less than or
equal
to the ending unit (RHS).
4. Unit numbers and ranges can be specified multiple times with
different
`modes`, with the last (rightmost) `exception` taking priority. For
example:
`FORT_CONVERT_UNIT="LITTLE_ENDIAN:10,11,15-20;BIG_ENDIAN:19"`
The conversion for unit 19 will be `BIG_ENDIAN`.
5. If an `exception` is not prefixed with `mode:`, `mode` is assumed to
be
`BIG_ENDIAN`. For example:
`FORT_CONVERT_UNIT="20-25;LITTLE_ENDIAN:26-27"`
Regardless of the host processor's endianness, units 20 through 25 will
be
treated as big-endian for both input and output, while units 26 and 27
will be
treated as little-endian for both input and output.
---------
Co-authored-by: Slava Zakharin <szakharin at nvidia.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list