]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: add F2023 ISO_FORTRAN_ENV named constants
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Tue, 19 Mar 2024 13:16:38 +0000 (14:16 +0100)
committerFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Mon, 29 Apr 2024 14:24:20 +0000 (16:24 +0200)
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.

gcc/fortran/iso-fortran-env.def
gcc/testsuite/gfortran.dg/iso_fortran_env_8.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/iso_fortran_env_9.f90 [new file with mode: 0644]

index ed7946a2594100dc90b90f814902957915359107..069bbc1fb86785b294d0c1fc09f4035fb77a197d 100644 (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", \
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 (file)
index 0000000..d3661b3
--- /dev/null
@@ -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 (file)
index 0000000..ffd70b2
--- /dev/null
@@ -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