[flang-commits] [flang] [llvm] Flang improve fidelity of unformatted I/O endianness with FORT_CONVERT_UNIT (PR #223831)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Sep 22 17:56:21 PDT 2026


vzakhari wrote:

Hi Dave! I tried building it for the device, and it failed right away. The diagnostic looks like this:
```
.../llvm-project/flang-rt/include/flang-rt/runtime/environment.h(52): error: constexpr constructor calls non-constexpr function "Fortran:
:runtime::DynamicArray<T>::DynamicArray() [with T=Fortran::runtime::ExecutionEnvironment::ConvertUnit]"
    constexpr ExecutionEnvironment() {};
                                     ^

1 error detected in the compilation of ".../llvm-project/flang-rt/lib/runtime/descriptor.cpp".
```

Basically, we cannot use DynamicArray as a member of ExecutionEnvironment in the device compilation. The recommendation is to use a raw pointer and a dynamically allocated memory to store the ConvertUnit objects, something like:
```
ConvertUnit *convertUnits{nullptr};
std::size_t numConvertUnits{0};
```

Here is a more detailed explanation of the problem:
1. Root cause of the reported error

The PR adds DynamicArray<ConvertUnit> convertUnits; to ExecutionEnvironment in [flang-rt/include/flang-rt/runtime/environment.h](/llvm/llvm-project/blob/main/flang-rt/include/flang-rt/runtime/environment.h). DynamicArray<T> embeds a Terminator terminator_{\_\_FILE\_\_, \_\_LINE\_\_} ([array.h:64](/llvm/llvm-project/blob/main/flang-rt/lib/runtime/array.h)), and Terminator's constructors are user-provided and non-constexpr ([terminator.h:27-30](/llvm/llvm-project/blob/main/flang-rt/include/flang-rt/runtime/terminator.h)). So DynamicArray<T>'s implicit default constructor is non-constexpr, which C++17 [dcl.constexpr]/4 forbids inside constexpr ExecutionEnvironment() {}.

2. Why the host build does not catch it

Because DynamicArray is a class template. Verified locally:
* Non-template equivalent: g++ 8.5 -std=c++17 errors with call to non-'constexpr' function 'A::A()'.
* Template equivalent (matching the real code): both g++ 8.5 and clang 21.1.8 accept it silently, applying the ill-formed-no-diagnostic-required relaxation of [dcl.constexpr]/6 to the implicitly-defined special member of a template specialization.
* nvcc 12.8 (EDG) enforces [dcl.constexpr]/4 strictly and produces the reported diagnostic.

https://github.com/llvm/llvm-project/pull/223831


More information about the flang-commits mailing list