Fortran: add F2023 ISO_FORTRAN_ENV named constants

gcc/fortran/ChangeLog:

	* iso-fortran-env.def: Add logical{8,16,32,64} and
	real16 named constants.

gcc/testsuite/ChangeLog:

	* gfortran.dg/iso_fortran_env_8.f90: New test.
	* gfortran.dg/iso_fortran_env_9.f90: New test.
This commit is contained in:
Francois-Xavier Coudert 2024-03-19 14:16:38 +01:00
parent f795049a82
commit 1dba1d860a
3 changed files with 71 additions and 0 deletions

View file

@ -68,10 +68,20 @@ NAMED_INTCST (ISOFORTRANENV_IOSTAT_EOR, "iostat_eor", LIBERROR_EOR, \
NAMED_INTCST (ISOFORTRANENV_IOSTAT_INQUIRE_INTERNAL_UNIT, \
"iostat_inquire_internal_unit", LIBERROR_INQUIRE_INTERNAL_UNIT, \
GFC_STD_F2008)
NAMED_INTCST (ISOFORTRANENV_LOGICAL8, "logical8", \
gfc_get_int_kind_from_width_isofortranenv (8), GFC_STD_F2023)
NAMED_INTCST (ISOFORTRANENV_LOGICAL16, "logical16", \
gfc_get_int_kind_from_width_isofortranenv (16), GFC_STD_F2023)
NAMED_INTCST (ISOFORTRANENV_LOGICAL32, "logical32", \
gfc_get_int_kind_from_width_isofortranenv (32), GFC_STD_F2023)
NAMED_INTCST (ISOFORTRANENV_LOGICAL64, "logical64", \
gfc_get_int_kind_from_width_isofortranenv (64), GFC_STD_F2023)
NAMED_INTCST (ISOFORTRANENV_NUMERIC_STORAGE_SIZE, "numeric_storage_size", \
gfc_numeric_storage_size, GFC_STD_F2003)
NAMED_INTCST (ISOFORTRANENV_OUTPUT_UNIT, "output_unit", GFC_STDOUT_UNIT_NUMBER, \
GFC_STD_F2003)
NAMED_INTCST (ISOFORTRANENV_REAL16, "real16", \
gfc_get_real_kind_from_width_isofortranenv (16), GFC_STD_F2023)
NAMED_INTCST (ISOFORTRANENV_REAL32, "real32", \
gfc_get_real_kind_from_width_isofortranenv (32), GFC_STD_F2008)
NAMED_INTCST (ISOFORTRANENV_REAL64, "real64", \

View file

@ -0,0 +1,32 @@
! { dg-do run }
!
! Check for the new Fortran 2023 ISO_FORTRAN_ENV named constants
program test
use iso_fortran_env
implicit none
! These integer kinds are guaranteed on
integer(int8) :: i8
integer(int16) :: i16
integer(int32) :: i32
integer(int64) :: i64
logical(logical8) :: l8
logical(logical16) :: l16
logical(logical32) :: l32
logical(logical64) :: l64
! We do not support REAL16 for now, but check it can
! still be used in specification expressions
real(kind=max(real16, real32)) :: x
if (logical8 /= int8) stop 1
if (logical16 /= int16) stop 2
if (logical32 /= int32) stop 3
if (logical64 /= int64) stop 4
! We do not support REAL16 for now
if (real16 /= -2) stop 101
end program test

View file

@ -0,0 +1,29 @@
! { dg-do compile }
! { dg-options "-std=f2018" }
!
! Check diagnostics for new F2023 named constants
! in ISO_FORTRAN_ENV
!
subroutine foo
use iso_fortran_env
implicit none
logical(kind=logical8) :: x ! { dg-error "has no IMPLICIT type" }
end subroutine
subroutine bar
use iso_fortran_env, only : logical8 ! { dg-error "not in the selected standard" }
use iso_fortran_env, only : logical16 ! { dg-error "not in the selected standard" }
use iso_fortran_env, only : logical32 ! { dg-error "not in the selected standard" }
use iso_fortran_env, only : logical64 ! { dg-error "not in the selected standard" }
use iso_fortran_env, only : real16 ! { dg-error "not in the selected standard" }
implicit none
end subroutine
subroutine gee
use iso_fortran_env, only : int8
use iso_fortran_env, only : int16
use iso_fortran_env, only : int32
use iso_fortran_env, only : int64
implicit none
end subroutine