From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id A5EA83858D20; Sat, 18 Nov 2023 22:12:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5EA83858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A5EA83858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700345578; cv=none; b=N6/40FYFYZ7kXl3eWe57MpvE+xsKT2ty8bNYFfqDxaC6ZAaymqlTTwbDHDQT2ati1hKVunYsdxcp1L4QMuIbcfIqpHiPDW6WpXQqyfT7VHb2dm083GsHcdlfgpomYRzm8uBWfx/HhvduwVHDesRgdEnFDsEn2OvkLSmWwzwy+uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700345578; c=relaxed/simple; bh=7J29oSeU/8B9u5ol7ibckMfhG+FBao6CdTCBIE0FtHk=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=sscKum9c2ML6QeNt1bE/9cJEJj8mhISu+qDB/h0AVs2vgLqE6FdVqDefJJlW5DdKXdZ4MbliUg4HNV6yQsD4qCKoRo9kQYfcYqZ3YIOfnVMegkZNSQx3Of0l3mbwRRtrO57bdR4CV/9tqSHvKmfnfyWU/yfYnTgCp/jR+9qomfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1700345575; x=1700950375; i=anlauf@gmx.de; bh=7J29oSeU/8B9u5ol7ibckMfhG+FBao6CdTCBIE0FtHk=; h=X-UI-Sender-Class:From:To:Subject:Date; b=Vf+Wj3jYsEvIj14/mBnihn/Xh8J+N1wgmppDYTvCUcsnFS1vFIwvF21RIvxzEXPj Pq5d787M6Jix7zBQlPhnowAQK/ckQNbf3Mlzge9Oz5ci+briOJC5wFUykxbK1M6yY KV7sqBx1x/nBo0sYbLewzpXJuN50I2ocqQE5xqikCrW0V4UNPe9koUxX1hYYDG81U /Wq6wUoUuEsldTiltaZGwmTDkGfB3MCxecsZQhtbuZOgZOMPGKhxdF2NyrRbo+QvD LoSi+aId3WL3gjQajWSts7je+lAL8zJDQGtaH3b8D8ZgRihTA4zuu/IuULbSDS0XT o4r++oizvndm/nkhrA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.232.157.67] ([79.232.157.67]) by web-mail.gmx.net (3c-app-gmx-bs41.server.lan [172.19.170.93]) (via HTTP); Sat, 18 Nov 2023 23:12:55 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] Content-Type: multipart/mixed; boundary=trekuen-a32e172c-31c7-4254-8004-262f909a06a4 Date: Sat, 18 Nov 2023 23:12:55 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:Tu53liiOqByddL7EK9u+q7s4bLnn9jA7i6JLFJtTHqivbKTmiGjH03XQyOkwmBqxaRdeu Vtn9bZbM116NtgoSLhPWRIwCNaPiUeIvHTHuise+K7U1pIH+l8JiFpiDYvzoo8chi948kmhi0OES e29ECd8RVcWfMEyksYtyOIx9wcKaPklEvxQJcKffxNijICcUtiLLX6NHpQbR/dIQC6I+pQHrhedV vJZktkGNR/1TsBo+6MV0yhbb4b+Z0u/BLzL/LDxiuZp6Q90i/uLSszIfaukcYrfIvXjVqHeyHe4K dE= UI-OutboundReport: notjunk:1;M01:P0:Ne7GCE1rRbk=;scy49hg0gORuJfPr2IRNhFpYEYv V4Sg3ZqDCnCB5NaT3AEGEZB00PJcIreNv6jkXoF1/RJjGhvpAAVnJFs3KuqdRHIpY5Vq6I+In PsWXMd2VwJfN6lqha3NQq70InZMQInzpGRKHSvYWHcJO1EsozVBcSq5T6HxQlKfJUoRp4sc7W aoViTnTN/gL3L/R847WEtir/pXnsqt+XG41ae8oO0+PUg7icLPvG+dIgis7lMNzH42sUL4y3c /WHYV1UOIevfvxTP6w3Gz5XdG6/SWbXlALAHoEbCG+YEUb6SDV6zF5kJBUK8XobfvhO5T5p+H 1zvm71d95NjtadJQB13EmPNWcDGGqF08Y+4dOV0XqNFy3LRWPsf8XKu5GXGRx+nb2hoEqqaKX x0hoD03HZAMQTOW+PGSH4vbDVGqZ8idf6hexMX7cIMNRkiofm5jkZhkT4qOWAS2p98OKNRdld l8y0WN2cQc3SedwBx2rAStUfv1yAa/8TapCJs24XHcykcXaOqoiNk0PsQ+SabIltrQHeXOKx2 OWqEsCYEwVp6CrbVwj5Kkry/AlldWx4s6iUKlHCK+ELrMSxdhI5XtxhexidnWc0vHCHEKvafV w13B9YejlilmC7PsFpn6CwtRdo2OHaeA3ItZbamS4lPS374kzkrNJ88rK98a4ngLPHE/xKuKi wWtY+52G44BVbi9jr84HqLsaDscDd0P4cdQJiIIyPetN8c+9qAW2zQEMkYyqpC5ciW62AdmWv v9GZiUCuEvPNmih1ye86Uoe9uo1c1hJJvDgUgmUwPPl/RatFUvvwHh0wELddDQ7ShL2CmOyWL qwFoZYd2GZZ/HHVxU+xWHVKA== X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --trekuen-a32e172c-31c7-4254-8004-262f909a06a4 Content-Type: text/plain; charset=UTF-8 Hi all, Fortran 2023 added restrictions on integer arguments to SYSTEM_CLOCK. The attached patch implements these. I was struggling with the way we should handle features that are sort-of deleted in a new standard, but not described as such in the standard, which is why we do not have GFC_STD_F2023_DEL. As -std=gnu should not apply this restriction, I came up with the solution in the patch. While playing, I hit a gcc_unreachable in notify_std_msg due to a missing case, also fixed. Interestingly, the standard now has a recommendation: 16.9.202 SYSTEM_CLOCK It it recommended that all references to SYSTEM_CLOCK use integer arguments with a decimal exponent range of at least 18. ... In case the user chooses integer(4), shall we emit a warning e.g. under -pedantic, or some other flag? This is not done in the patch, but could be added. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --trekuen-a32e172c-31c7-4254-8004-262f909a06a4 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr112609.diff Content-Transfer-Encoding: quoted-printable =46rom 44814d9436b2e0be14b76b137602e40f3fdaf805 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 18 Nov 2023 22:51:35 +0100 Subject: [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOC= K [PR112609] Fortran 2023 added restrictions on integer arguments to SYSTEM_CLOCK to have a decimal exponent range at least as large as a default integer, and that all integer arguments have the same kind type parameter. gcc/fortran/ChangeLog: PR fortran/112609 * check.cc (gfc_check_system_clock): Add checks on integer arguments to SYSTEM_CLOCK specific to F2023. * error.cc (notify_std_msg): Adjust to handle new features added in F2023. gcc/testsuite/ChangeLog: PR fortran/112609 * gfortran.dg/system_clock_4.f90: New test. =2D-- gcc/fortran/check.cc | 57 ++++++++++++++++++++ gcc/fortran/error.cc | 4 +- gcc/testsuite/gfortran.dg/system_clock_4.f90 | 24 +++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/system_clock_4.f90 diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index 6c45e6542f0..8c2534ae1c9 100644 =2D-- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -6774,6 +6774,10 @@ bool gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate, gfc_expr *count_max) { + int first_int_kind =3D -1; + bool f2023 =3D ((gfc_option.allow_std & GFC_STD_F2023) !=3D 0 + && (gfc_option.allow_std & GFC_STD_GNU) =3D=3D 0); + if (count !=3D NULL) { if (!scalar_check (count, 0)) @@ -6788,8 +6792,18 @@ gfc_check_system_clock (gfc_expr *count, gfc_expr *= count_rate, &count->where)) return false; + if (f2023 && count->ts.kind < gfc_default_integer_kind) + { + gfc_error ("Fortran 2023: COUNT argument to SYSTEM_CLOCK " + "at %L must have kind of at least default integer", + &count->where); + return false; + } + if (!variable_check (count, 0, false)) return false; + + first_int_kind =3D count->ts.kind; } if (count_rate !=3D NULL) @@ -6816,6 +6830,17 @@ gfc_check_system_clock (gfc_expr *count, gfc_expr *= count_rate, "SYSTEM_CLOCK at %L has non-default kind", &count_rate->where)) return false; + + if (f2023 && count_rate->ts.kind < gfc_default_integer_kind) + { + gfc_error ("Fortran 2023: COUNT_RATE argument to SYSTEM_CLOCK " + "at %L must have kind of at least default integer", + &count_rate->where); + return false; + } + + if (first_int_kind < 0) + first_int_kind =3D count_rate->ts.kind; } } @@ -6836,6 +6861,38 @@ gfc_check_system_clock (gfc_expr *count, gfc_expr *= count_rate, if (!variable_check (count_max, 2, false)) return false; + + if (f2023 && count_max->ts.kind < gfc_default_integer_kind) + { + gfc_error ("Fortran 2023: COUNT_MAX argument to SYSTEM_CLOCK " + "at %L must have kind of at least default integer", + &count_max->where); + return false; + } + + if (first_int_kind < 0) + first_int_kind =3D count_max->ts.kind; + } + + if (f2023 && first_int_kind > 0) + { + if (count_rate + && count_rate->ts.type =3D=3D BT_INTEGER + && count_rate->ts.kind !=3D first_int_kind) + { + gfc_error ("Fortran 2023: all integer arguments to SYSTEM_CLOCK " + "at %L must have the same kind", + &count_rate->where); + return false; + } + + if (count_max && count_max->ts.kind !=3D first_int_kind) + { + gfc_error ("Fortran 2023: all integer arguments to SYSTEM_CLOCK " + "at %L must have the same kind", + &count_max->where); + return false; + } } return true; diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index 2ac51e95e4d..b8b36c0cd7c 100644 =2D-- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -980,7 +980,9 @@ char const* notify_std_msg(int std) { - if (std & GFC_STD_F2018_DEL) + if (std & GFC_STD_F2023) + return _("Fortran 2023:"); + else if (std & GFC_STD_F2018_DEL) return _("Fortran 2018 deleted feature:"); else if (std & GFC_STD_F2018_OBS) return _("Fortran 2018 obsolescent feature:"); diff --git a/gcc/testsuite/gfortran.dg/system_clock_4.f90 b/gcc/testsuite/= gfortran.dg/system_clock_4.f90 new file mode 100644 index 00000000000..f2d706f6d8c =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/system_clock_4.f90 @@ -0,0 +1,24 @@ +! { dg-do compile } +! { dg-options "-std=3Df2023" } +! PR fortran/112609 - F2023 restrictions on integer arguments to SYSTEM_C= LOCK + +program p + implicit none + integer :: i, j, k + integer(2) :: i2, j2, k2 + integer(8) :: i8, j8, k8 + real :: x + + call system_clock(count=3Di2) ! { dg-error "at least default integ= er" } + call system_clock(count_rate=3Dj2) ! { dg-error "at least default integ= er" } + call system_clock(count_max=3Dk2) ! { dg-error "at least default integ= er" } + + call system_clock(count=3Di8,count_rate=3Dx,count_max=3Dk8) + call system_clock(count=3Di, count_rate=3Dj8) ! { dg-error "must ha= ve the same kind" } + call system_clock(count=3Di8,count_rate=3Dj) ! { dg-error "must ha= ve the same kind" } + call system_clock(count=3Di, count_max=3Dk8) ! { dg-error "must ha= ve the same kind" } + call system_clock(count=3Di8,count_max=3Dk) ! { dg-error "must ha= ve the same kind" } + call system_clock(count_rate=3Dj, count_max=3Dk8) ! { dg-error "must ha= ve the same kind" } + call system_clock(count_rate=3Dj8,count_max=3Dk) ! { dg-error "must ha= ve the same kind" } + call system_clock(i,x,k8) ! { dg-error "must have t= he same kind" } +end =2D- 2.35.3 --trekuen-a32e172c-31c7-4254-8004-262f909a06a4--