From patchwork Sun Nov 19 20:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1865803 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=qdMQQjdX; 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 4SYN446jl8z1yRl for ; Mon, 20 Nov 2023 07:47:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B419385701B for ; Sun, 19 Nov 2023 20:47: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.19]) by sourceware.org (Postfix) with ESMTPS id D41A7385800C; Sun, 19 Nov 2023 20:46:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D41A7385800C 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 D41A7385800C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700426817; cv=none; b=lPtVh1qe6IXJM14se2kY8pWYoAM0kGjvy4MiNv57O7leK+oZdFTSPgYGsuaagnmw16hYs5kYfXQWw5x0sDpYEq61OD+/ANLGeBO0Dd4GytzdG02VP8P7bMFg6evabQeQg3v6NXA8e3vhvCGswcvrKjzVcpcMClvsHFInei3I4Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700426817; c=relaxed/simple; bh=vwdgA+o+BcjAlonEQRHEJI2bxILpvKJvmJlUr9HpGdo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=wUSmRmF3dqS1ZhJa2YI3QDbwNqsPcKVSiUqOey+TcJfsa9pktcUafKwzuTOacNhQnacLf/QDCYImPARPBB3fvbKFKOZQkQaNs3EfRb4RVQqqJ8m9lkrF2bzQ5NvU3Fikk/fPHynGrabtsSClIjtDtP+A7RrEzdD6y3HY/pcrDuU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1700426808; x=1701031608; i=anlauf@gmx.de; bh=vwdgA+o+BcjAlonEQRHEJI2bxILpvKJvmJlUr9HpGdo=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From: In-Reply-To; b=qdMQQjdXNQKqNbKs3zHgPVjSETszxek0sdlpEhuVdWWAYdi3DthR5Qsl5PXXtcMn ULZMYxXdFcZpyn05N4KhYn+TtfeJLWYs62z/jNpPHImQLGZCzRUi05fFkZRnu6Fyv UQCRlqvTSgc3j9SWT7FsBE8AhPKFWRiB6GpJKODSaAWaJQONS/UMwHPYqOcoCcF9v RciDfW+aIL58W6wbVgPNGaTaAJwVwBDYO2JVc4dPVDx4Y2xkokYefpW7yeMMwd/Rt NtCcedNNaXRThcZ8xwhMV3Du6yshgnzA/ZYOUc4XYXB9p8sbIrMLXKulR1IXTS3HQ 8hyESTR8FzzysTy77w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.156.163]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N49h5-1rVWfp2Uxl-0103cs; Sun, 19 Nov 2023 21:46:48 +0100 Message-ID: <2898e351-eee8-45dd-a05d-0280378ba872@gmx.de> Date: Sun, 19 Nov 2023 21:46:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH, v2] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] To: sgk@troutmask.apl.washington.edu Cc: fortran , gcc-patches Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: Content-Language: en-US From: Harald Anlauf In-Reply-To: X-Provags-ID: V03:K1:p0iIk+S1OGrApPzQqt36MsKi4jZhaeMSyfQv6ENXDf4ZlCVPP6B Iixt/vFBTx3I+fueamyQh3zx35z+CdZBxGXcrYBdvOg6USijaqp/U5dK4lVG2foKq2SUcKa fA5+G4THPPoLPRKnV/C5JpSIvNpyS0Ont+4cq62JtV6U5ahV/J5p+W0B8Ugp54sB+7rQCuH ddxBb7leaRZBeR/qbfQqw== UI-OutboundReport: notjunk:1;M01:P0:oY6uE4R6npU=;PwHAiL4FoAgeMI0UVVnbvvrNf7b 8ZdZKyu4pnLiwDDC3ERVrbsMXfWscn+YbL8h+5gxBp68NVRTklGO6SeeojBCJrCAbWL/Vdyig VT19pQdt8/Qg9XcxLBZquBmH1R0xWoQ1k4niAPGqOdFEHG7D9cbTxMTutyPr4wt2VlP/CgOCf +7H1rYdmUpDwShCvbtYT8QnN6JsXX1VV23WwSau9nf3RzmSUZ/8hO0r6b9l48B+mu9nCDeHO0 Rpw/4j6JvzuAyNDqaty/hDMCwa2q7Km5zG42ul6kYrK9egzeZSwtiGGajFk8oXfzCuB3FVhXX bkB86Rt8jWa7OD2TNX+uQ4FM8Y78ezbgb/n203CnCm5vuESy8+ieIL3ILecDxejBv6GpyS3Nz A10OnmzseAdi6id2Uy3yV+j3+FmrZyz7rxJDG6LM7tVL8n/pLY0AuTdWo1P7xSTB7b83ryR2M Bj0N/tm3HfMLMGIpZ+dyL7JRlWkvBX1ibVZoMbCjK3V7D4L30kvxeKR+trsX4l6DTVd+RAw5c JCN1uzBlI1TgOjT0rlzrST/nchCXBlMWd6m2HG+1tK/kd94dMhXUXOAP5V9NjsEQdXztyOmuL hV0M2TuEe6hrdRSka+ycQh2lH3rIo8O2UkkjqAVAOa9wQT1M1c3qF4AV3qyNY++CAfH5ey/oh 8Os2CzQ9uc3LSKYPYdgJ9LzF1X4TTXPeoGguP7HJ4VCxhVfmznOVirun0ef2UPhKe3zsgPIoF BxbmyBDEaGM0iGCBnlrogo0Oq6mXKw8DgTwbq//Feln9ccJcqq51YgEYrTT741GDrXfg/4Nb9 0wpYBQ4aYlWs7AUTzsdRyM2ZzmtfY34DgQ/kHov+Ndqf05W63bEznqlOVsikQFkRj8nQowoTJ FV+rG1+LPPhxfwuhLtUdXI+cyODtth1lGij5jT41dBN1e48ZZQCA35UO//fguyPP/41kRISoz szOjM1AHt1B6Q2C3YIG7deJKwlc= X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 Steve, On 11/19/23 01:04, Steve Kargl wrote: > On Sat, Nov 18, 2023 at 11:12:55PM +0100, Harald Anlauf wrote: >> Regtested on x86_64-pc-linux-gnu. OK for mainline? >> > > Not in its current form. > >> { >> + int first_int_kind = -1; >> + bool f2023 = ((gfc_option.allow_std & GFC_STD_F2023) != 0 >> + && (gfc_option.allow_std & GFC_STD_GNU) == 0); >> + > > If you use the gfc_notify_std(), then you should not need the > above check on GFC_STD_GNU as it should include GFC_STD_F2023. this is actually the question (and problem). For all new features, -std=gnu shall include everything allowed by -std=f2023. Here we have the problem that the testcase is valid F2018 and is silently accepted by gfortran-13 for -std=gnu and -std=f2018. I prefer to keep it that way also for gfortran-14, and apply the new restrictions only for -std=f2023. Do we agree on this? Now that should happen for -std=gnu -pedantic (-w)? I have thought some more and came up with the revised attached patch, which still has the above condition. It now marks the diagnostics as GNU extensions beyond F2023 for -std=f2023. The mask f2023 in the above form suppresses new warnings even for -pedantic; one would normally use -w to suppress them. Now if you remove the second part of the condition, we will regress on testcases system_clock_1.f90 and system_clock_3.f90 because they would emit GNU extension warnings because the testsuite runs with -pedantic. The options I see: - use patch-V1 (although diagnostics are better in V2), - use patch-V2, - use patch-V2, but enable -pedantic warnings for previously valid code, and adjust the failing testcases - ??? > Elsewhere in the FE, gfortran uses gfc_notify_std() to enforce > requirements of a Fortran standard. The above would be > > if (count->ts.kind < gfc_default_integer_kind > && gfc_notify_std (GFC_STD_F2023, "COUNT argument to SYSTEM_CLOCK " > "at %L must have kind of at least default integer", > &count->where)) I tried this first, and it did not do the job. The logic in gfc_notify_std is: estd = std & ~gfc_option.allow_std; /* Standard to error about. */ error = (estd != 0); if (error) msg = notify_std_msg (estd); ... So for -std=f2023 we get estd=0, error=false, and *NO* error. For -std=f2018 we get error=true and an error message. This is the opposite of what is needed. Can you please try yourself? > Note, gfc_notify_std() should add the 'Fortran 2023: ' string, > if not, that should be fixed. This I did fix. > Of course, I seldom provide patches if others don't have a comment > then do as you like. Thanks for your feedback! Harald From 2a85dc469696c85524459380ce11faa20e558680 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 19 Nov 2023 21:14:37 +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 | 52 ++++++++++++++++++++ gcc/fortran/error.cc | 4 +- gcc/testsuite/gfortran.dg/system_clock_4.f90 | 24 +++++++++ 3 files changed, 79 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..faaea853bc4 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,17 @@ 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_notify_std (GFC_STD_GNU, "Fortran 2023 requires " + "COUNT argument to SYSTEM_CLOCK at %L " + "to have a 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 +6829,16 @@ 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_notify_std (GFC_STD_GNU, "Fortran 2023 requires " + "COUNT_RATE argument to SYSTEM_CLOCK at %L " + "to have a 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 +6859,35 @@ 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_notify_std (GFC_STD_GNU, "Fortran 2023 requires " + "COUNT_MAX argument to SYSTEM_CLOCK at %L " + "to have a 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_notify_std (GFC_STD_GNU, "Fortran 2023 requires " + "all integer arguments to SYSTEM_CLOCK " + "at %L to have the same kind", + &count_rate->where)) + return false; + + if (count_max && count_max->ts.kind != first_int_kind + && !gfc_notify_std (GFC_STD_GNU, "Fortran 2023 requires " + "all integer arguments to SYSTEM_CLOCK " + "at %L to 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..d4496efbe2a --- /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 "have the same kind" } + call system_clock(count=i8,count_rate=j) ! { dg-error "have the same kind" } + call system_clock(count=i, count_max=k8) ! { dg-error "have the same kind" } + call system_clock(count=i8,count_max=k) ! { dg-error "have the same kind" } + call system_clock(count_rate=j, count_max=k8) ! { dg-error "have the same kind" } + call system_clock(count_rate=j8,count_max=k) ! { dg-error "have the same kind" } + call system_clock(i,x,k8) ! { dg-error "have the same kind" } +end -- 2.35.3