https://gcc.gnu.org/g:1dba1d860a1e3e32e5d061a1d6dc600c96d2597f

commit r15-50-g1dba1d860a1e3e32e5d061a1d6dc600c96d2597f
Author: Francois-Xavier Coudert <fxcoud...@gcc.gnu.org>
Date:   Tue Mar 19 14:16:38 2024 +0100

    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.

Diff:
---
 gcc/fortran/iso-fortran-env.def                 | 10 ++++++++
 gcc/testsuite/gfortran.dg/iso_fortran_env_8.f90 | 32 +++++++++++++++++++++++++
 gcc/testsuite/gfortran.dg/iso_fortran_env_9.f90 | 29 ++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/gcc/fortran/iso-fortran-env.def b/gcc/fortran/iso-fortran-env.def
index ed7946a2594..069bbc1fb86 100644
--- a/gcc/fortran/iso-fortran-env.def
+++ b/gcc/fortran/iso-fortran-env.def
@@ -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", \
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_env_8.f90 
b/gcc/testsuite/gfortran.dg/iso_fortran_env_8.f90
new file mode 100644
index 00000000000..d3661b3b592
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_env_8.f90
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_env_9.f90 
b/gcc/testsuite/gfortran.dg/iso_fortran_env_9.f90
new file mode 100644
index 00000000000..ffd70b23159
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_env_9.f90
@@ -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

Reply via email to