* [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] @ 2023-11-18 22:12 Harald Anlauf 2023-11-19 0:04 ` Steve Kargl 0 siblings, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-18 22:12 UTC (permalink / raw) To: fortran, gcc-patches [-- Attachment #1: Type: text/plain, Size: 920 bytes --] 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 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: pr112609.diff --] [-- Type: text/x-patch, Size: 5721 bytes --] From 44814d9436b2e0be14b76b137602e40f3fdaf805 Mon Sep 17 00:00:00 2001 From: Harald Anlauf <anlauf@gmx.de> 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-18 22:12 [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] Harald Anlauf @ 2023-11-19 0:04 ` Steve Kargl 2023-11-19 20:46 ` [PATCH, v2] " Harald Anlauf 0 siblings, 1 reply; 13+ messages in thread From: Steve Kargl @ 2023-11-19 0:04 UTC (permalink / raw) To: Harald Anlauf; +Cc: fortran, gcc-patches On Sat, Nov 18, 2023 at 11:12:55PM +0100, Harald Anlauf wrote: > > 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? > 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. > > + 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; > + } 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)) Note, gfc_notify_std() should add the 'Fortran 2023: ' string, if not, that should be fixed. Of course, I seldom provide patches if others don't have a comment then do as you like. -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH, v2] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-19 0:04 ` Steve Kargl @ 2023-11-19 20:46 ` Harald Anlauf 2023-11-20 19:02 ` Steve Kargl 0 siblings, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-19 20:46 UTC (permalink / raw) To: sgk; +Cc: fortran, gcc-patches [-- Attachment #1: Type: text/plain, Size: 2803 bytes --] 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 [-- Attachment #2: pr112609-v2.diff --] [-- Type: text/x-patch, Size: 5692 bytes --] From 2a85dc469696c85524459380ce11faa20e558680 Mon Sep 17 00:00:00 2001 From: Harald Anlauf <anlauf@gmx.de> 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v2] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-19 20:46 ` [PATCH, v2] " Harald Anlauf @ 2023-11-20 19:02 ` Steve Kargl 2023-11-21 11:33 ` Mikael Morin 0 siblings, 1 reply; 13+ messages in thread From: Steve Kargl @ 2023-11-20 19:02 UTC (permalink / raw) To: Harald Anlauf; +Cc: fortran, gcc-patches Harald, Sorry about delayed response. Got side-tracked by Family this weekend. On Sun, Nov 19, 2023 at 09:46:46PM +0100, Harald Anlauf wrote: > > 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. Yes. > Here we have the problem that the testcase is valid F2018 and is > silently accepted by gfortran-13 for -std=gnu and -std=f2018. F2023 is the Fortran standard and supercedes previous Fortran standards. If there is a conflict between the standing standard and an old standard, then the standing standard should take precedence unless one specifically uses, for example, -std=f2018. After 20+ years of contributing to gfortran, I've come to believe that the default -std= should be the current standard, and -std=gnu should be deprecated. All GNU extensions should require an option to active. For example, write(*,*), 'hello' end gfortran12 -o z a.f90 a.f90:1:10: 1 | write(*,*), 'hello' | 1 Warning: Legacy Extension: Comma before i/o item list at (1) This should be an error unless the -fallow-write-stmt-comma is used. The option would simply degrade the error to a warning. Why, you ask? To encourage people to write standard conforming code. Unfortunately, that horse has left the barn. > 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? If gfortran wants to maintain the status quo for 14, then it should probably remove the -std=f2023 patch and wait for the branch to 15. > Now that should happen for -std=gnu -pedantic (-w)? -pedantic is not a very effective option and should be ignored. > 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. It seems that the solution is to fix the code in the testsuite. With -std=f2023 or -std=gnu, the code should error. With -std=f2018 (or older?), the code should compile. It's been too long for my memory, doesn't the use of '{ dg-options "-std=f023" }' supercede the set of predefined options such as -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 I suppose that this last one is the best option. > > - ??? > > > 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? > I was afraid you were going to say this. :-) :-) The holidays draw near. I can probably find the time to poke at gfortran. > > Note, gfc_notify_std() should add the 'Fortran 2023: ' string, > > if not, that should be fixed. > > This I did fix. Thanks. > > Of course, I seldom provide patches if others don't have a comment > > then do as you like. > > Thanks for your feedback! No, thank you for continuing to peck away at gfortran issue. -- steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v2] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-20 19:02 ` Steve Kargl @ 2023-11-21 11:33 ` Mikael Morin 2023-11-21 21:54 ` [PATCH, v3] " Harald Anlauf 0 siblings, 1 reply; 13+ messages in thread From: Mikael Morin @ 2023-11-21 11:33 UTC (permalink / raw) To: sgk, Harald Anlauf; +Cc: fortran, gcc-patches Hello, Le 20/11/2023 à 20:02, Steve Kargl a écrit : > Harald, > > Sorry about delayed response. Got side-tracked by Family this weekend. > > On Sun, Nov 19, 2023 at 09:46:46PM +0100, Harald Anlauf wrote: >> >> 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. > > Yes. > Harald, you mentioned the lack of GFC_STD_F2023_DEL feature group in your first message, but I don't quite understand why you didn't add one. It seems to me the most natural way to do this. >> Here we have the problem that the testcase is valid F2018 and is >> silently accepted by gfortran-13 for -std=gnu and -std=f2018. > > F2023 is the Fortran standard and supercedes previous Fortran standards. > If there is a conflict between the standing standard and an old standard, > then the standing standard should take precedence unless one specifically > uses, for example, -std=f2018. > > After 20+ years of contributing to gfortran, I've come to believe > that the default -std= should be the current standard, and -std=gnu > should be deprecated. All GNU extensions should require an option > to active. For example, > > write(*,*), 'hello' > end > > gfortran12 -o z a.f90 > a.f90:1:10: > > 1 | write(*,*), 'hello' > | 1 > Warning: Legacy Extension: Comma before i/o item list at (1) > > This should be an error unless the -fallow-write-stmt-comma is used. > The option would simply degrade the error to a warning. Why, you ask? > To encourage people to write standard conforming code. Unfortunately, > that horse has left the barn. > >> 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? > I suggest we emit a warning by default, error with -std=f2023 (I agree with Steve that we should push towards strict f2023 conformance), and no diagnostic with -std=gnu or -std=f2018 or lower. > If gfortran wants to maintain the status quo for 14, then > it should probably remove the -std=f2023 patch and wait for > the branch to 15. > >> Now that should happen for -std=gnu -pedantic (-w)? > > -pedantic is not a very effective option and should be ignored. > >> 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. > > It seems that the solution is to fix the code in the testsuite. Agreed, these seem to explicitly test mismatching kinds, so add an option to prevent error. Mikael ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-21 11:33 ` Mikael Morin @ 2023-11-21 21:54 ` Harald Anlauf 2023-11-21 22:09 ` Harald Anlauf 0 siblings, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-21 21:54 UTC (permalink / raw) To: Mikael Morin, sgk; +Cc: fortran, gcc-patches [-- Attachment #1: Type: text/plain, Size: 1228 bytes --] Hi Mikael, Steve, On 11/21/23 12:33, Mikael Morin wrote: > Harald, you mentioned the lack of GFC_STD_F2023_DEL feature group in > your first message, but I don't quite understand why you didn't add one. > It seems to me the most natural way to do this. thanks for insisting on this variant. In my first attack at this problem, I overlooked one place in libgfortran.h, which I now was able to find and adjust. Now everything falls into place. > I suggest we emit a warning by default, error with -std=f2023 (I agree > with Steve that we should push towards strict f2023 conformance), and no > diagnostic with -std=gnu or -std=f2018 or lower. As the majority agrees on this, I accept it. The attached patch now does this and fixes the testcases accordingly. >> It seems that the solution is to fix the code in the testsuite. > > Agreed, these seem to explicitly test mismatching kinds, so add an > option to prevent error. Done. I also fixed a few issues in the documentation in gfortran.texi . As I currently cannot build a full compiler (see PR112643), patch V3 is not properly regtested yet, but appears to give results as discussed. Comments? > Mikael Thanks, Harald [-- Attachment #2: pr104819-v3.patch --] [-- Type: text/x-patch, Size: 11057 bytes --] diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index 6c45e6542f0..e5cf6a495b5 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -4357,6 +4357,9 @@ gfc_check_null (gfc_expr *mold) if (mold == NULL) return true; + if (mold->expr_type == EXPR_NULL) + return true; + if (!variable_check (mold, 0, true)) return false; @@ -5189,7 +5192,7 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr) { *msg = NULL; - if (expr->expr_type == EXPR_NULL) + if (expr->expr_type == EXPR_NULL && expr->ts.type == BT_UNKNOWN) { *msg = "NULL() is not interoperable"; return false; diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index fc4fe662eab..641edf9d059 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -2387,6 +2387,8 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, gfc_component *ppc; bool codimension = false; gfc_array_spec *formal_as; + bool pointer_arg, allocatable_arg; + bool pre2018 = ((gfc_option.allow_std & GFC_STD_F2018) == 0); /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding procs c_f_pointer or c_f_procpointer, and we need to accept most @@ -2564,13 +2566,20 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, } } + pointer_arg = gfc_expr_attr (actual).pointer; + allocatable_arg = gfc_expr_attr (actual).allocatable; + /* F08: 12.5.2.5 Allocatable and pointer dummy variables. However, this is necessary also for F03, so retain error for both. + F2018:15.5.2.5 relaxes this constraint to same attributes. NOTE: Other type/kind errors pre-empt this error. Since they are F03 compatible, no attempt has been made to channel to this one. */ if (UNLIMITED_POLY (formal) && !UNLIMITED_POLY (actual) && (CLASS_DATA (formal)->attr.allocatable - ||CLASS_DATA (formal)->attr.class_pointer)) + || CLASS_DATA (formal)->attr.class_pointer) + && (pre2018 + || (allocatable_arg && CLASS_DATA (formal)->attr.allocatable) + || (pointer_arg && CLASS_DATA (formal)->attr.class_pointer))) { if (where) gfc_error ("Actual argument to %qs at %L must be unlimited " @@ -2710,7 +2719,8 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, rank_check = where != NULL && !is_elemental && formal_as && (formal_as->type == AS_ASSUMED_SHAPE || formal_as->type == AS_DEFERRED) - && actual->expr_type != EXPR_NULL; + && !(actual->expr_type == EXPR_NULL + && actual->ts.type == BT_UNKNOWN); /* Skip rank checks for NO_ARG_CHECK. */ if (formal->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK)) @@ -3184,8 +3194,10 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, gfc_array_ref *actual_arr_ref; gfc_array_spec *fas, *aas; bool pointer_dummy, pointer_arg, allocatable_arg; + bool procptr_dummy, optional_dummy, allocatable_dummy; bool ok = true; + bool pre2018 = ((gfc_option.allow_std & GFC_STD_F2018) == 0); actual = *ap; @@ -3296,15 +3308,66 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, && a->expr->ts.type != BT_ASSUMED) gfc_find_vtab (&a->expr->ts); + /* Checks for NULL() actual arguments without MOLD. */ + if (a->expr->expr_type == EXPR_NULL && a->expr->ts.type == BT_UNKNOWN) + { + /* Interp J3/22-146: + "If the context of the reference to NULL is an <actual argument> + corresponding to an <assumed-rank> dummy argument, MOLD shall be + present." */ + fas = (f->sym->ts.type == BT_CLASS && CLASS_DATA (f->sym) + ? CLASS_DATA (f->sym)->as + : f->sym->as); + if (fas && fas->type == AS_ASSUMED_RANK) + { + gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument " + "at %L passed to assumed-rank dummy %qs", + &a->expr->where, f->sym->name); + ok = false; + goto match; + } + + /* Asummed-length dummy argument. */ + if (f->sym->ts.type == BT_CHARACTER + && !f->sym->ts.deferred + && f->sym->ts.u.cl + && f->sym->ts.u.cl->length == NULL) + { + gfc_error ("Intrinsic %<NULL()%> without %<MOLD%> argument " + "at %L passed to assumed-length dummy %qs", + &a->expr->where, f->sym->name); + ok = false; + goto match; + } + } + + /* Allow passing of NULL() as disassociated pointer, procedure + pointer, or unallocated allocatable (F2008+) to a respective dummy + argument. */ + pointer_dummy = ((f->sym->ts.type != BT_CLASS + && f->sym->attr.pointer) + || (f->sym->ts.type == BT_CLASS + && CLASS_DATA (f->sym)->attr.class_pointer)); + + procptr_dummy = ((f->sym->ts.type != BT_CLASS + && f->sym->attr.proc_pointer) + || (f->sym->ts.type == BT_CLASS + && CLASS_DATA (f->sym)->attr.proc_pointer)); + + optional_dummy = f->sym->attr.optional; + + allocatable_dummy = ((f->sym->ts.type != BT_CLASS + && f->sym->attr.allocatable) + || (f->sym->ts.type == BT_CLASS + && CLASS_DATA (f->sym)->attr.allocatable)); + if (a->expr->expr_type == EXPR_NULL - && ((f->sym->ts.type != BT_CLASS && !f->sym->attr.pointer - && (f->sym->attr.allocatable || !f->sym->attr.optional - || (gfc_option.allow_std & GFC_STD_F2008) == 0)) - || (f->sym->ts.type == BT_CLASS - && !CLASS_DATA (f->sym)->attr.class_pointer - && (CLASS_DATA (f->sym)->attr.allocatable - || !f->sym->attr.optional - || (gfc_option.allow_std & GFC_STD_F2008) == 0)))) + && !pointer_dummy + && !procptr_dummy + && !(optional_dummy + && (gfc_option.allow_std & GFC_STD_F2008) != 0) + && !(allocatable_dummy + && (gfc_option.allow_std & GFC_STD_F2008) != 0)) { if (where && (!f->sym->attr.optional @@ -3409,6 +3472,9 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, if (f->sym->ts.type == BT_CLASS) goto skip_size_check; + if (a->expr->expr_type == EXPR_NULL) + goto skip_size_check; + actual_size = get_expr_storage_size (a->expr); formal_size = get_sym_storage_size (f->sym); if (actual_size != 0 && actual_size < formal_size @@ -3606,6 +3672,71 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, } } + /* Check conditions on allocatable and pointer dummy variables: + + "The actual argument shall be polymorphic if and only if the + associated dummy argument is polymorphic, and either both the + actual and dummy arguments shall be unlimited polymorphic, or the + declared type of the actual argument shall be the same as the + declared type of the dummy argument." + + with a minor difference from F2008:15.5.2.5 to F2018:15.5.2.5, + where the latter applies only to same (ALLOCATABLE or POINTER) + attributes. Note that checks related to unlimited polymorphism + are also done in compare_parameter(). */ + if ((pointer_dummy || allocatable_dummy) + && (pointer_arg || allocatable_arg) + && (pre2018 + || (pointer_dummy && pointer_arg) + || (allocatable_dummy && allocatable_arg)) + && (f->sym->ts.type == BT_CLASS + || a->expr->ts.type == BT_CLASS)) + { + if (f->sym->ts.type == BT_CLASS && a->expr->ts.type != BT_CLASS + && pointer_dummy) + { + if (where) + gfc_error ("Actual argument to %qs at %L must be a " + "CLASS POINTER", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + + if (f->sym->ts.type != BT_CLASS && a->expr->ts.type == BT_CLASS + && pointer_arg) + { + if (where) + gfc_error ("Actual argument to %qs at %L cannot be a " + "CLASS POINTER", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + + if (f->sym->ts.type == BT_CLASS && a->expr->ts.type != BT_CLASS + && allocatable_dummy) + { + if (where) + gfc_error ("Actual argument to %qs at %L must be a " + "CLASS ALLOCATABLE", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + + if (f->sym->ts.type != BT_CLASS && a->expr->ts.type == BT_CLASS + && allocatable_arg) + { + if (where) + gfc_error ("Actual argument to %qs at %L cannot be a " + "CLASS ALLOCATABLE", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + } + /* Fortran 2008, C1242. */ if (f->sym->attr.pointer && gfc_is_coindexed (a->expr)) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 50c4604a025..30b941356b6 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6288,16 +6288,37 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, && (fsym->ts.type != BT_CLASS || !CLASS_DATA (fsym)->attr.class_pointer)) { - /* Pass a NULL pointer to denote an absent arg. */ - gcc_assert (fsym->attr.optional && !fsym->attr.allocatable - && (fsym->ts.type != BT_CLASS - || !CLASS_DATA (fsym)->attr.allocatable)); - gfc_init_se (&parmse, NULL); - parmse.expr = null_pointer_node; - if (arg->associated_dummy - && gfc_dummy_arg_get_typespec (*arg->associated_dummy).type - == BT_CHARACTER) - parmse.string_length = build_int_cst (gfc_charlen_type_node, 0); + if ((fsym->ts.type != BT_CLASS + && fsym->attr.allocatable) + || (fsym->ts.type == BT_CLASS + && CLASS_DATA (fsym)->attr.allocatable)) + { + /* Pass descriptor equivalent to an unallocated allocatable + actual argument. */ + if (e->rank != 0) + gfc_internal_error ("gfc_conv_procedure_call() TODO: " + "NULL(allocatable(rank != 0))"); + /* Scalar version below. */ + gfc_init_se (&parmse, NULL); + gfc_conv_expr_reference (&parmse, e); + tmp = parmse.expr; + if (TREE_CODE (tmp) == ADDR_EXPR) + tmp = TREE_OPERAND (tmp, 0); + parmse.expr = gfc_conv_scalar_to_descriptor (&parmse, tmp, + fsym->attr); + parmse.expr = gfc_build_addr_expr (NULL_TREE, parmse.expr); + } + else + { + /* Pass a NULL pointer to denote an absent optional arg. */ + gcc_assert (fsym->attr.optional); + gfc_init_se (&parmse, NULL); + parmse.expr = null_pointer_node; + if (arg->associated_dummy + && gfc_dummy_arg_get_typespec (*arg->associated_dummy).type + == BT_CHARACTER) + parmse.string_length = build_int_cst (gfc_charlen_type_node, 0); + } } else if (fsym && fsym->ts.type == BT_CLASS && e->ts.type == BT_DERIVED) @@ -6852,7 +6873,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, we can assign it to the data field. */ if (fsym && fsym->as && fsym->as->type == AS_ASSUMED_RANK - && fsym->ts.type != BT_CLASS && e->expr_type != EXPR_NULL) + && fsym->ts.type != BT_CLASS + && !(e->expr_type == EXPR_NULL + && e->ts.type == BT_UNKNOWN)) { tmp = parmse.expr; if (TREE_CODE (tmp) == ADDR_EXPR) ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-21 21:54 ` [PATCH, v3] " Harald Anlauf @ 2023-11-21 22:09 ` Harald Anlauf 2023-11-22 9:36 ` Mikael Morin 0 siblings, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-21 22:09 UTC (permalink / raw) To: Mikael Morin, sgk; +Cc: fortran, gcc-patches [-- Attachment #1: Type: text/plain, Size: 1439 bytes --] Uhh, it happened again. Attached a wrong patch. Only looked at the -v3 ... My bad. Sorry! Harald On 11/21/23 22:54, Harald Anlauf wrote: > Hi Mikael, Steve, > > On 11/21/23 12:33, Mikael Morin wrote: >> Harald, you mentioned the lack of GFC_STD_F2023_DEL feature group in >> your first message, but I don't quite understand why you didn't add one. >> It seems to me the most natural way to do this. > > thanks for insisting on this variant. > > In my first attack at this problem, I overlooked one place in > libgfortran.h, which I now was able to find and adjust. > Now everything falls into place. > >> I suggest we emit a warning by default, error with -std=f2023 (I agree >> with Steve that we should push towards strict f2023 conformance), and no >> diagnostic with -std=gnu or -std=f2018 or lower. > > As the majority agrees on this, I accept it. The attached patch > now does this and fixes the testcases accordingly. > >>> It seems that the solution is to fix the code in the testsuite. >> >> Agreed, these seem to explicitly test mismatching kinds, so add an >> option to prevent error. > > Done. > > I also fixed a few issues in the documentation in gfortran.texi . > > As I currently cannot build a full compiler (see PR112643), > patch V3 is not properly regtested yet, but appears to give > results as discussed. > > Comments? > >> Mikael > > Thanks, > Harald > > [-- Attachment #2: pr112609-v3.diff --] [-- Type: text/x-patch, Size: 10764 bytes --] From 8fbffe1bd1faaff456abf6730ac2e2b3c370bc72 Mon Sep 17 00:00:00 2001 From: Harald Anlauf <anlauf@gmx.de> Date: Tue, 21 Nov 2023 22:29:19 +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 | 8 ++-- 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(+), 11 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..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:"); + 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..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. 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)) -#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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 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:36 ` [PATCH, v4] " Harald Anlauf 0 siblings, 2 replies; 13+ messages in thread From: Mikael Morin @ 2023-11-22 9:36 UTC (permalink / raw) To: Harald Anlauf, sgk; +Cc: fortran, gcc-patches Le 21/11/2023 à 23:09, Harald Anlauf a écrit : > Uhh, it happened again. Attached a wrong patch. > Only looked at the -v3 ... My bad. > > Sorry! > > Harald > > > On 11/21/23 22:54, Harald Anlauf wrote: >> Hi Mikael, Steve, >> >> On 11/21/23 12:33, Mikael Morin wrote: >>> Harald, you mentioned the lack of GFC_STD_F2023_DEL feature group in >>> your first message, but I don't quite understand why you didn't add one. >>> It seems to me the most natural way to do this. >> >> thanks for insisting on this variant. >> >> In my first attack at this problem, I overlooked one place in >> libgfortran.h, which I now was able to find and adjust. >> Now everything falls into place. >> >>> I suggest we emit a warning by default, error with -std=f2023 (I agree >>> with Steve that we should push towards strict f2023 conformance), and no >>> diagnostic with -std=gnu or -std=f2018 or lower. >> >> As the majority agrees on this, I accept it. The attached patch >> now does this and fixes the testcases accordingly. >> >>>> It seems that the solution is to fix the code in the testsuite. >>> >>> Agreed, these seem to explicitly test mismatching kinds, so add an >>> option to prevent error. >> >> Done. >> >> I also fixed a few issues in the documentation in gfortran.texi . >> >> As I currently cannot build a full compiler (see PR112643), >> patch V3 is not properly regtested yet, but appears to give >> results as discussed. >> >> Comments? >> >>> Mikael >> >> Thanks, >> Harald >> >> > (...) > 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:"); > 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). OK with this fixed (and the previous comments as you wish), if Steve has no more comments. Thanks for the patch. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 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:36 ` [PATCH, v4] " Harald Anlauf 1 sibling, 1 reply; 13+ messages in thread From: Steve Kargl @ 2023-11-22 18:03 UTC (permalink / raw) To: Mikael Morin; +Cc: Harald Anlauf, fortran, gcc-patches On Wed, Nov 22, 2023 at 10:36:00AM +0100, Mikael Morin wrote: > > OK with this fixed (and the previous comments as you wish), if Steve has no > more comments. > No further comments. Thanks for your patients, Harald. As side note, I found John Reid's "What's new" document where it is noted that there are no new obsolescent or delete features. https://wg5-fortran.org/N2201-N2250/N2212.pdf -- Steve ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-22 18:03 ` Steve Kargl @ 2023-11-22 20:40 ` Harald Anlauf 2023-11-22 20:40 ` Harald Anlauf 0 siblings, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-22 20:40 UTC (permalink / raw) To: sgk, Mikael Morin; +Cc: fortran, gcc-patches Hi Steve, On 11/22/23 19:03, Steve Kargl wrote: > On Wed, Nov 22, 2023 at 10:36:00AM +0100, Mikael Morin wrote: >> >> OK with this fixed (and the previous comments as you wish), if Steve has no >> more comments. >> > > No further comments. Thanks for your patients, Harald. > > As side note, I found John Reid's "What's new" document > where it is noted that there are no new obsolescent or > delete features. > > https://wg5-fortran.org/N2201-N2250/N2212.pdf > this is good to know. There is an older version (still referring to F202x) on the wiki: https://gcc.gnu.org/wiki/GFortranStandards It would be great if someone with editing permission could update the link and point to the above. Thanks, Harald ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v3] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-22 20:40 ` Harald Anlauf @ 2023-11-22 20:40 ` Harald Anlauf 0 siblings, 0 replies; 13+ messages in thread From: Harald Anlauf @ 2023-11-22 20:40 UTC (permalink / raw) To: fortran; +Cc: gcc-patches, fortran Hi Steve, On 11/22/23 19:03, Steve Kargl wrote: > On Wed, Nov 22, 2023 at 10:36:00AM +0100, Mikael Morin wrote: >> >> OK with this fixed (and the previous comments as you wish), if Steve has no >> more comments. >> > > No further comments. Thanks for your patients, Harald. > > As side note, I found John Reid's "What's new" document > where it is noted that there are no new obsolescent or > delete features. > > https://wg5-fortran.org/N2201-N2250/N2212.pdf > this is good to know. There is an older version (still referring to F202x) on the wiki: https://gcc.gnu.org/wiki/GFortranStandards It would be great if someone with editing permission could update the link and point to the above. Thanks, Harald ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH, v4] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-22 9:36 ` Mikael Morin 2023-11-22 18:03 ` Steve Kargl @ 2023-11-22 20:36 ` Harald Anlauf 2023-11-23 9:07 ` Mikael Morin 1 sibling, 1 reply; 13+ messages in thread From: Harald Anlauf @ 2023-11-22 20:36 UTC (permalink / raw) To: Mikael Morin, sgk; +Cc: fortran, gcc-patches [-- 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH, v4] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] 2023-11-22 20:36 ` [PATCH, v4] " Harald Anlauf @ 2023-11-23 9:07 ` Mikael Morin 0 siblings, 0 replies; 13+ messages in thread From: Mikael Morin @ 2023-11-23 9:07 UTC (permalink / raw) To: Harald Anlauf, sgk; +Cc: fortran, gcc-patches Le 22/11/2023 à 21:36, Harald Anlauf a écrit : > 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. > Ah, yes. I confused the GFC_STD_OPT* values with the GFC_STD_* ones. >> 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 > Thanks again. ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-11-23 9:07 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-11-18 22:12 [PATCH] Fortran: restrictions on integer arguments to SYSTEM_CLOCK [PR112609] Harald Anlauf 2023-11-19 0:04 ` Steve Kargl 2023-11-19 20:46 ` [PATCH, v2] " 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 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 ` [PATCH, v4] " Harald Anlauf 2023-11-23 9:07 ` Mikael Morin
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).