[Flang] `real(kind=16)` fails to cross-compile
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When using Flang built on X86_64 to cross-compile for AArch64, `real(kind=16)` and `complex(kind=16)` result in compilation errors.
- CMakeFile
```
cmake \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/ \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
-DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
-DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-linux-gnu" \
//llvm-project/llvm
```
- foo.f90
```fortran
program main
real(kind=16) :: r
complex(kind=16) :: c
end program
```
- Compilation error
```
$ flang --target=aarch64-unknown-linux-gnu --sysroot=/libc --gcc-toolchain= foo.f90 -c -o x86_to_aarch.o
error: Semantic errors in foo.f90
./foo.f90:2:3: error: REAL(KIND=16) is not an enabled type for this target
real(kind=16) :: r
^^^^^^^^^^^^^^^^^^
./foo.f90:3:3: error: COMPLEX(KIND=16) is not an enabled type for this target
complex(kind=16) :: c
^^^^^^^^^^^^^^^^^^^^^
```
This seems to be caused by flang checking the C `long double` type of the build environment to determine if 128-bit computation is possible.
The actual checks are performed in [FlangCommon.cmake](https://github.com/llvm/llvm-project/blob/e2040f5ba3c4f54599776e6f4118881c501bf1f8/flang/cmake/modules/FlangCommon.cmake#L30-L42) and [f18/CMakeList.txt](https://github.com/llvm/llvm-project/blob/28373708280a52ecd3181591f7c3935ffceafbcc/flang/tools/f18/CMakeLists.txt#L28-L36). Ideally, it should check the type information of the target environment, not the build environment, to build.
Also, I'm concerned about whether Flang can correctly determine the available types for each target when built for multiple target architectures. This might be a similar issue to [#158790](https://github.com/llvm/llvm-project/issues/158790).
Contributor guide
Research direction
Start with flang/cmake/modules/FlangCommon.cmake lines 30-42 and flang/tools/f18/CMakeLists.txt lines 28-36, then reproduce the x86_64-to-AArch64 build using the supplied CMake configuration and foo.f90. Trace how the build environment's long double information enables REAL(KIND=16) and COMPLEX(KIND=16). Done means cross-compilation selects appropriate target type information without the reported errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100