IEEE-754 binary16 ("half") maps cleanly to the C `_Float16` type
(ISO/IEC TS 18661-3), but flang previously rejected `REAL(KIND=2)` and
`COMPLEX(KIND=2)` in C-interoperable contexts. Make `REAL(KIND=2)` and
`COMPLEX(KIND=2)` into actual interoperable types.
`ISO_C_BINDING` now exports the gfortran-compatible named constants
`c_float16` and `c_float16_complex` (both value 2), the kind parameter
for the half-precision C interoperable types.
Assisted-by: AI
31 lines
1 KiB
Fortran
31 lines
1 KiB
Fortran
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
|
|
! REAL(KIND=2)/COMPLEX(KIND=2) (IEEE binary16) are interoperable with C
|
|
! _Float16, and ISO_C_BINDING exports c_float16/c_float16_complex (value 2).
|
|
! Verify no diagnostic (including no portability warning under -pedantic),
|
|
! while bfloat16 (KIND=3) stays non-interoperable.
|
|
module m
|
|
use iso_c_binding, only: c_float16, c_float16_complex
|
|
integer, parameter :: check = c_float16
|
|
real(kind=2), bind(c) :: a
|
|
complex(kind=2), bind(c) :: b
|
|
real(c_float16), bind(c) :: c
|
|
complex(c_float16_complex), bind(c) :: d
|
|
|
|
type, bind(c) :: t1
|
|
real(kind=2) :: x
|
|
complex(kind=2) :: y
|
|
end type
|
|
|
|
type, bind(c) :: t2
|
|
!ERROR: Each component of an interoperable derived type must have an interoperable type
|
|
real(kind=3) :: x ! bfloat16 is not interoperable
|
|
end type
|
|
|
|
interface
|
|
subroutine s(x, y) bind(c)
|
|
import :: c_float16, c_float16_complex
|
|
real(c_float16), value :: x
|
|
complex(c_float16_complex), value :: y
|
|
end subroutine
|
|
end interface
|
|
end
|