From patchwork Sat Nov 18 22:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1865594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=anlauf@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=Vf+Wj3jY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SXp1l3LqYz1yRg for ; Sun, 19 Nov 2023 09:13:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 988983857C77 for ; Sat, 18 Nov 2023 22:13:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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] 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 From 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_CLOCK [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. --- 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 --- 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 = -1; + bool f2023 = ((gfc_option.allow_std & GFC_STD_F2023) != 0 + && (gfc_option.allow_std & GFC_STD_GNU) == 0); + if (count != 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 = count->ts.kind; } if (count_rate != 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 = 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 = count_max->ts.kind; + } + + if (f2023 && first_int_kind > 0) + { + if (count_rate + && count_rate->ts.type == BT_INTEGER + && count_rate->ts.kind != 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 != 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 --- 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 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/system_clock_4.f90 @@ -0,0 +1,24 @@ +! { dg-do compile } +! { dg-options "-std=f2023" } +! PR fortran/112609 - F2023 restrictions on integer arguments to SYSTEM_CLOCK + +program p + implicit none + integer :: i, j, k + integer(2) :: i2, j2, k2 + integer(8) :: i8, j8, k8 + real :: x + + call system_clock(count=i2) ! { dg-error "at least default integer" } + call system_clock(count_rate=j2) ! { dg-error "at least default integer" } + call system_clock(count_max=k2) ! { dg-error "at least default integer" } + + call system_clock(count=i8,count_rate=x,count_max=k8) + call system_clock(count=i, count_rate=j8) ! { dg-error "must have the same kind" } + call system_clock(count=i8,count_rate=j) ! { dg-error "must have the same kind" } + call system_clock(count=i, count_max=k8) ! { dg-error "must have the same kind" } + call system_clock(count=i8,count_max=k) ! { dg-error "must have the same kind" } + call system_clock(count_rate=j, count_max=k8) ! { dg-error "must have the same kind" } + call system_clock(count_rate=j8,count_max=k) ! { dg-error "must have the same kind" } + call system_clock(i,x,k8) ! { dg-error "must have the same kind" } +end -- 2.35.3