Issue 160060
Summary [Flang] `real(kind=16)` fails to cross-compile
Labels flang
Assignees
Reporter s-watanabe314
    
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=/<install_dir> \
 -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_dir>/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=<GCC_TOOLCHAIN_DIR>/libc --gcc-toolchain=<GCC_TOOLCHAIN_DIR> 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).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to