From: Harald Anlauf <anlauf@gmx.de>
To: Mikael Morin <morin-mikael@orange.fr>, sgk@troutmask.apl.washington.edu
Cc: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, v4] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609]
Date: Wed, 22 Nov 2023 21:36:27 +0100 [thread overview]
Message-ID: <956bd0e6-d53d-4df9-b952-f441b7e3fac4@gmx.de> (raw)
Message-ID: <20231122203627.t8LWXaWOdEqp_kwYTaaSW9AMJ2tIUBn6CDMjLh7rr-M@z> (raw)
In-Reply-To: <97809d56-b3dc-42c9-85e8-6eb8bc618428@orange.fr>
[-- Attachment #1: Type: text/plain, Size: 3699 bytes --]
Hi Mikael!
On 11/22/23 10:36, Mikael Morin wrote:
> (...)
>
>> diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
>> index 2ac51e95e4d..be715b50469 100644
>> --- a/gcc/fortran/error.cc
>> +++ b/gcc/fortran/error.cc
>> @@ -980,7 +980,11 @@ char const*
>> notify_std_msg(int std)
>> {
>>
>> - if (std & GFC_STD_F2018_DEL)
>> + if (std & GFC_STD_F2023_DEL)
>> + return _("Fortran 2023 deleted feature:");
>
> As there are officially no deleted feature in f2023, maybe use a
> slightly different wording? Say "Not allowed in fortran 2023" or
> "forbidden in Fortran 2023" or similar?
>
>> + else 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:");
I skimmed over existing error messages, and since "forbidden" did
not show up and since "Not allowed" exists but not at the beginning
of a message, I found that
"Prohibited in Fortran 2023"
appeared to be a good alternative.
Not being a native speaker, I hope that someone speaks up if this
is not appropriate. And since I do not explicitly verify that part
in the testcase, it can be changed.
>> diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h
>> index bdddb317ab0..af7a170c2b1 100644
>> --- a/gcc/fortran/libgfortran.h
>> +++ b/gcc/fortran/libgfortran.h
>> @@ -19,9 +19,10 @@ along with GCC; see the file COPYING3. If not see
>>
>>
>> /* Flags to specify which standard/extension contains a feature.
>> - Note that no features were obsoleted nor deleted in F2003 nor in
>> F2023.
>> + Note that no features were obsoleted nor deleted in F2003.
>
> I think we can add a comment that F2023 has no deleted feature, but some
> more stringent restrictions in f2023 forbid some previously valid code.
>
>> Please remember to keep those definitions in sync with
>> gfortran.texi. */
>> +#define GFC_STD_F2023_DEL (1<<13) /* Deleted in F2023. */
>> #define GFC_STD_F2023 (1<<12) /* New in F2023. */
>> #define GFC_STD_F2018_DEL (1<<11) /* Deleted in F2018. */
>> #define GFC_STD_F2018_OBS (1<<10) /* Obsolescent in F2018. */
>> @@ -41,12 +42,13 @@ along with GCC; see the file COPYING3. If not see
>> * are allowed with a certain -std option. */
>> #define GFC_STD_OPT_F95 (GFC_STD_F77 | GFC_STD_F95 |
>> GFC_STD_F95_OBS \
>> | GFC_STD_F2008_OBS | GFC_STD_F2018_OBS \
>> - | GFC_STD_F2018_DEL)
>> + | GFC_STD_F2018_DEL | GFC_STD_F2023_DEL)
>> #define GFC_STD_OPT_F03 (GFC_STD_OPT_F95 | GFC_STD_F2003)
>> #define GFC_STD_OPT_F08 (GFC_STD_OPT_F03 | GFC_STD_F2008)
>> #define GFC_STD_OPT_F18 ((GFC_STD_OPT_F08 | GFC_STD_F2018) \
>> & (~GFC_STD_F2018_DEL))
> F03, F08 and F18 should have GFC_STD_F2023_DEL (and also F03 and F08
> should have GFC_STD_F2018_DEL).
Well, these macros do an incremental bitwise-or, so the bit representing
GFC_STD_F2023_DEL is included everywhere. I also ran the testcases with
different -std= options to check.
> OK with this fixed (and the previous comments as you wish), if Steve has
> no more comments.
>
> Thanks for the patch.
>
>
If there are no further comments, I will commit once I am able to
fully build again with --disable-bootstrap and -march=native ...
Thanks,
Harald
[-- Attachment #2: pr112609-v4.diff --]
[-- Type: text/x-patch, Size: 10775 bytes --]
From 56386f4f332cf8970a424ba67678335fa6186e4c Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 22 Nov 2023 20:57:59 +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.
* gfortran.texi (_gfortran_set_options): Document GFC_STD_F2023_DEL,
remove obsolete option GFC_STD_F2008_TS and fix enumeration values.
* libgfortran.h (GFC_STD_F2023_DEL): Add and use in GFC_STD_OPT_F23.
* options.cc (set_default_std_flags): Add GFC_STD_F2023_DEL.
gcc/testsuite/ChangeLog:
PR fortran/112609
* gfortran.dg/system_clock_1.f90: Add option -std=f2003.
* gfortran.dg/system_clock_3.f08: Add option -std=f2008.
* gfortran.dg/system_clock_4.f90: New test.
---
gcc/fortran/check.cc | 50 ++++++++++++++++++++
gcc/fortran/error.cc | 6 ++-
gcc/fortran/gfortran.texi | 10 ++--
gcc/fortran/libgfortran.h | 7 ++-
gcc/fortran/options.cc | 6 ++-
gcc/testsuite/gfortran.dg/system_clock_1.f90 | 1 +
gcc/testsuite/gfortran.dg/system_clock_3.f08 | 1 +
gcc/testsuite/gfortran.dg/system_clock_4.f90 | 24 ++++++++++
8 files changed, 95 insertions(+), 10 deletions(-)
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..3b1a0f9f4f4 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -6774,6 +6774,8 @@ bool
gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
gfc_expr *count_max)
{
+ int first_int_kind = -1;
+
if (count != NULL)
{
if (!scalar_check (count, 0))
@@ -6788,8 +6790,17 @@ gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
&count->where))
return false;
+ if (count->ts.kind < gfc_default_integer_kind
+ && !gfc_notify_std (GFC_STD_F2023_DEL,
+ "COUNT argument to SYSTEM_CLOCK at %L "
+ "with kind smaller than 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 +6827,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 (count_rate->ts.kind < gfc_default_integer_kind
+ && !gfc_notify_std (GFC_STD_F2023_DEL,
+ "COUNT_RATE argument to SYSTEM_CLOCK at %L "
+ "with kind smaller than default integer",
+ &count_rate->where))
+ return false;
+
+ if (first_int_kind < 0)
+ first_int_kind = count_rate->ts.kind;
}
}
@@ -6836,6 +6857,35 @@ gfc_check_system_clock (gfc_expr *count, gfc_expr *count_rate,
if (!variable_check (count_max, 2, false))
return false;
+
+ if (count_max->ts.kind < gfc_default_integer_kind
+ && !gfc_notify_std (GFC_STD_F2023_DEL,
+ "COUNT_MAX argument to SYSTEM_CLOCK at %L "
+ "with kind smaller than default integer",
+ &count_max->where))
+ return false;
+
+ if (first_int_kind < 0)
+ first_int_kind = count_max->ts.kind;
+ }
+
+ if (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_F2023_DEL,
+ "integer arguments to SYSTEM_CLOCK at %L "
+ "with different kind parameters",
+ &count_rate->where))
+ return false;
+
+ if (count_max && count_max->ts.kind != first_int_kind
+ && !gfc_notify_std (GFC_STD_F2023_DEL,
+ "integer arguments to SYSTEM_CLOCK at %L "
+ "with different kind parameters",
+ &count_max->where))
+ return false;
}
return true;
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index 2ac51e95e4d..56d2e63622d 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -980,7 +980,11 @@ char const*
notify_std_msg(int std)
{
- if (std & GFC_STD_F2018_DEL)
+ if (std & GFC_STD_F2023_DEL)
+ return _("Prohibited in Fortran 2023:");
+ else 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/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 41857cc9038..c29cb786279 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -3476,13 +3476,13 @@ standard. Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
@code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4),
@code{GFC_STD_F95} (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU}
(32), @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
-@code{GFC_STD_F2008_OBS} (256), @code{GFC_STD_F2008_TS} (512),
-@code{GFC_STD_F2018} (1024), @code{GFC_STD_F2018_OBS} (2048),
-@code{GFC_STD=F2018_DEL} (4096), and @code{GFC_STD=F2023} (8192).
+@code{GFC_STD_F2008_OBS} (256), @code{GFC_STD_F2018} (512),
+@code{GFC_STD_F2018_OBS} (1024), @code{GFC_STD_F2018_DEL} (2048),
+@code{GFC_STD_F2023} (4096), and @code{GFC_STD_F2023_DEL} (8192).
Default: @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 |
-GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS
+GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F2008_OBS
| GFC_STD_F77 | GFC_STD_F2018 | GFC_STD_F2018_OBS | GFC_STD_F2018_DEL
-| GFC_STD_F2023 | GFC_STD_GNU | GFC_STD_LEGACY}.
+| GFC_STD_F2023 | GFC_STD_F2023_DEL | GFC_STD_GNU | GFC_STD_LEGACY}.
@item @var{option}[1] @tab Standard-warning flag; prints a warning to
standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
@item @var{option}[2] @tab If non zero, enable pedantic checking.
diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h
index bdddb317ab0..2c71b90a871 100644
--- a/gcc/fortran/libgfortran.h
+++ b/gcc/fortran/libgfortran.h
@@ -20,8 +20,10 @@ along with GCC; see the file COPYING3. If not see
/* Flags to specify which standard/extension contains a feature.
Note that no features were obsoleted nor deleted in F2003 nor in F2023.
+ Nevertheless, some features available in F2018 are prohibited in F2023.
Please remember to keep those definitions in sync with
gfortran.texi. */
+#define GFC_STD_F2023_DEL (1<<13) /* Prohibited in F2023. */
#define GFC_STD_F2023 (1<<12) /* New in F2023. */
#define GFC_STD_F2018_DEL (1<<11) /* Deleted in F2018. */
#define GFC_STD_F2018_OBS (1<<10) /* Obsolescent in F2018. */
@@ -41,12 +43,13 @@ along with GCC; see the file COPYING3. If not see
* are allowed with a certain -std option. */
#define GFC_STD_OPT_F95 (GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F95_OBS \
| GFC_STD_F2008_OBS | GFC_STD_F2018_OBS \
- | GFC_STD_F2018_DEL)
+ | GFC_STD_F2018_DEL | GFC_STD_F2023_DEL)
#define GFC_STD_OPT_F03 (GFC_STD_OPT_F95 | GFC_STD_F2003)
#define GFC_STD_OPT_F08 (GFC_STD_OPT_F03 | GFC_STD_F2008)
#define GFC_STD_OPT_F18 ((GFC_STD_OPT_F08 | GFC_STD_F2018) \
& (~GFC_STD_F2018_DEL))
-#define GFC_STD_OPT_F23 (GFC_STD_OPT_F18 | GFC_STD_F2023)
+#define GFC_STD_OPT_F23 ((GFC_STD_OPT_F18 | GFC_STD_F2023) \
+ & (~GFC_STD_F2023_DEL))
/* Bitmasks for the various FPE that can be enabled. These need to be straight integers
e.g., 8 instead of (1<<3), because they will be included in Fortran source. */
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index b788521e816..02a29f83b58 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -57,8 +57,10 @@ set_default_std_flags (void)
gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
| GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
| GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY
- | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS | GFC_STD_F2023;
- gfc_option.warn_std = GFC_STD_F2018_DEL | GFC_STD_F95_DEL | GFC_STD_LEGACY;
+ | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS | GFC_STD_F2023
+ | GFC_STD_F2023_DEL;
+ gfc_option.warn_std = GFC_STD_F2018_DEL | GFC_STD_F95_DEL | GFC_STD_LEGACY
+ | GFC_STD_F2023_DEL;
}
/* Set (or unset) the DEC extension flags. */
diff --git a/gcc/testsuite/gfortran.dg/system_clock_1.f90 b/gcc/testsuite/gfortran.dg/system_clock_1.f90
index 41027deb28f..0cb0145e881 100644
--- a/gcc/testsuite/gfortran.dg/system_clock_1.f90
+++ b/gcc/testsuite/gfortran.dg/system_clock_1.f90
@@ -1,4 +1,5 @@
! { dg-do run }
+! { dg-options "-std=f2003" }
integer :: i, j, k
integer(kind=8) :: i8, j8, k8
diff --git a/gcc/testsuite/gfortran.dg/system_clock_3.f08 b/gcc/testsuite/gfortran.dg/system_clock_3.f08
index e52a51a7da4..c12849b77ab 100644
--- a/gcc/testsuite/gfortran.dg/system_clock_3.f08
+++ b/gcc/testsuite/gfortran.dg/system_clock_3.f08
@@ -1,4 +1,5 @@
! { dg-do run }
+! { dg-options "-std=f2008" }
! PR64432
program countem
implicit none
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..1bb42efac95
--- /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 "kind smaller than default integer" }
+ call system_clock(count_rate=j2) ! { dg-error "kind smaller than default integer" }
+ call system_clock(count_max=k2) ! { dg-error "kind smaller than default integer" }
+
+ call system_clock(count=i8,count_rate=x,count_max=k8)
+ call system_clock(count=i, count_rate=j8) ! { dg-error "different kind" }
+ call system_clock(count=i8,count_rate=j) ! { dg-error "different kind" }
+ call system_clock(count=i, count_max=k8) ! { dg-error "different kind" }
+ call system_clock(count=i8,count_max=k) ! { dg-error "different kind" }
+ call system_clock(count_rate=j, count_max=k8) ! { dg-error "different kind" }
+ call system_clock(count_rate=j8,count_max=k) ! { dg-error "different kind" }
+ call system_clock(i,x,k8) ! { dg-error "different kind" }
+end
--
2.35.3
next prev parent reply other threads:[~2023-11-22 20:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-18 22:12 [PATCH] " Harald Anlauf
2023-11-19 0:04 ` Steve Kargl
2023-11-19 20:46 ` [PATCH, v2] " Harald Anlauf
2023-11-19 20:46 ` Harald Anlauf
2023-11-20 19:02 ` Steve Kargl
2023-11-21 11:33 ` Mikael Morin
2023-11-21 21:54 ` [PATCH, v3] " Harald Anlauf
2023-11-21 21:54 ` Harald Anlauf
2023-11-21 22:09 ` Harald Anlauf
2023-11-21 22:09 ` Harald Anlauf
2023-11-22 9:36 ` Mikael Morin
2023-11-22 18:03 ` Steve Kargl
2023-11-22 20:40 ` Harald Anlauf
2023-11-22 20:40 ` Harald Anlauf
2023-11-22 20:36 ` Harald Anlauf [this message]
2023-11-22 20:36 ` [PATCH, v4] " Harald Anlauf
2023-11-23 9:07 ` Mikael Morin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=956bd0e6-d53d-4df9-b952-f441b7e3fac4@gmx.de \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=morin-mikael@orange.fr \
--cc=sgk@troutmask.apl.washington.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).