public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: force error on bad KIND specifier [PR88552]
@ 2023-06-01 19:05 Harald Anlauf
  2023-06-01 20:33 ` Mikael Morin
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2023-06-01 19:05 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

Dear all,

we sometimes silently accept wrong declarations with unbalanced
parentheses, as the PR and testcases therein show.

It appears that the fix is obvious: use the existing error paths in
gfc_match_kind_spec and error return from gfc_match_decl_type_spec.
I'm still posting it here in case I have missed something not so
obvious.

The patch regtests cleanly on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr88552.diff --]
[-- Type: text/x-patch, Size: 1786 bytes --]

From a30ff5af130c4d33c086fd136978d5f49cb8bde4 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 1 Jun 2023 20:56:11 +0200
Subject: [PATCH] Fortran: force error on bad KIND specifier [PR88552]

gcc/fortran/ChangeLog:

	PR fortran/88552
	* decl.cc (gfc_match_kind_spec): Use error path on missing right
	parenthesis.
	(gfc_match_decl_type_spec): Use error return when an error occurred
	during matching a KIND specifier.

gcc/testsuite/ChangeLog:

	PR fortran/88552
	* gfortran.dg/pr88552.f90: New test.
---
 gcc/fortran/decl.cc                   | 4 ++++
 gcc/testsuite/gfortran.dg/pr88552.f90 | 6 ++++++
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr88552.f90

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 1de2b231242..deb20647fb9 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3366,6 +3366,7 @@ close_brackets:
       else
 	gfc_error ("Missing right parenthesis at %C");
       m = MATCH_ERROR;
+      goto no_match;
     }
   else
      /* All tests passed.  */
@@ -4716,6 +4717,9 @@ get_kind:
       return MATCH_ERROR;
     }

+  if (m == MATCH_ERROR)
+    return MATCH_ERROR;
+
   /* Defer association of the KIND expression of function results
      until after USE and IMPORT statements.  */
   if ((gfc_current_state () == COMP_NONE && gfc_error_flag_test ())
diff --git a/gcc/testsuite/gfortran.dg/pr88552.f90 b/gcc/testsuite/gfortran.dg/pr88552.f90
new file mode 100644
index 00000000000..15e1b372f8f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr88552.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/88552
+! Contributed by G.Steinmetz
+
+integer(len((c)) :: n   ! { dg-error "must be CHARACTER" }
+end
--
2.35.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran: force error on bad KIND specifier [PR88552]
  2023-06-01 19:05 [PATCH] Fortran: force error on bad KIND specifier [PR88552] Harald Anlauf
@ 2023-06-01 20:33 ` Mikael Morin
  2023-06-01 21:11   ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Morin @ 2023-06-01 20:33 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Hello,

Le 01/06/2023 à 21:05, Harald Anlauf via Fortran a écrit :
> Dear all,
> 
> we sometimes silently accept wrong declarations with unbalanced
> parentheses, as the PR and testcases therein show.
> 
> It appears that the fix is obvious: use the existing error paths in
> gfc_match_kind_spec and error return from gfc_match_decl_type_spec.
> I'm still posting it here in case I have missed something not so
> obvious.
> 
> The patch regtests cleanly on x86_64-pc-linux-gnu.  OK for mainline?
> 
It looks good, but...

> Thanks,
> Harald
> 
> From a30ff5af130c4d33c086fd136978d5f49cb8bde4 Mon Sep 17 00:00:00 2001
> From: Harald Anlauf <anlauf@gmx.de>
> Date: Thu, 1 Jun 2023 20:56:11 +0200
> Subject: [PATCH] Fortran: force error on bad KIND specifier [PR88552]
> 
> gcc/fortran/ChangeLog:
> 
> 	PR fortran/88552
> 	* decl.cc (gfc_match_kind_spec): Use error path on missing right
> 	parenthesis.
> 	(gfc_match_decl_type_spec): Use error return when an error occurred
> 	during matching a KIND specifier.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR fortran/88552
> 	* gfortran.dg/pr88552.f90: New test.
> ---
>  gcc/fortran/decl.cc                   | 4 ++++
>  gcc/testsuite/gfortran.dg/pr88552.f90 | 6 ++++++
>  2 files changed, 10 insertions(+)
>  create mode 100644 gcc/testsuite/gfortran.dg/pr88552.f90
> 
> diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
> index 1de2b231242..deb20647fb9 100644
> --- a/gcc/fortran/decl.cc
> +++ b/gcc/fortran/decl.cc
> @@ -3366,6 +3366,7 @@ close_brackets:
>        else
>  	gfc_error ("Missing right parenthesis at %C");
>        m = MATCH_ERROR;
> +      goto no_match;
>      }
>    else
>       /* All tests passed.  */
> @@ -4716,6 +4717,9 @@ get_kind:
>        return MATCH_ERROR;
>      }
> 
> +  if (m == MATCH_ERROR)
> +    return MATCH_ERROR;
> +
... can you move this up to the place where m is set?
OK with that change.

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fortran: force error on bad KIND specifier [PR88552]
  2023-06-01 20:33 ` Mikael Morin
@ 2023-06-01 21:11   ` Harald Anlauf
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2023-06-01 21:11 UTC (permalink / raw)
  To: Mikael Morin, fortran, gcc-patches

Hi Mikael,

Am 01.06.23 um 22:33 schrieb Mikael Morin:
> Hello,
>
> Le 01/06/2023 à 21:05, Harald Anlauf via Fortran a écrit :
>> Dear all,
>>
>> we sometimes silently accept wrong declarations with unbalanced
>> parentheses, as the PR and testcases therein show.
>>
>> It appears that the fix is obvious: use the existing error paths in
>> gfc_match_kind_spec and error return from gfc_match_decl_type_spec.
>> I'm still posting it here in case I have missed something not so
>> obvious.
>>
>> The patch regtests cleanly on x86_64-pc-linux-gnu.  OK for mainline?
>>
> It looks good, but...
>
>> Thanks,
>> Harald
>>
>> From a30ff5af130c4d33c086fd136978d5f49cb8bde4 Mon Sep 17 00:00:00 2001
>> From: Harald Anlauf <anlauf@gmx.de>
>> Date: Thu, 1 Jun 2023 20:56:11 +0200
>> Subject: [PATCH] Fortran: force error on bad KIND specifier [PR88552]
>>
>> gcc/fortran/ChangeLog:
>>
>>     PR fortran/88552
>>     * decl.cc (gfc_match_kind_spec): Use error path on missing right
>>     parenthesis.
>>     (gfc_match_decl_type_spec): Use error return when an error occurred
>>     during matching a KIND specifier.
>>
>> gcc/testsuite/ChangeLog:
>>
>>     PR fortran/88552
>>     * gfortran.dg/pr88552.f90: New test.
>> ---
>>  gcc/fortran/decl.cc                   | 4 ++++
>>  gcc/testsuite/gfortran.dg/pr88552.f90 | 6 ++++++
>>  2 files changed, 10 insertions(+)
>>  create mode 100644 gcc/testsuite/gfortran.dg/pr88552.f90
>>
>> diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
>> index 1de2b231242..deb20647fb9 100644
>> --- a/gcc/fortran/decl.cc
>> +++ b/gcc/fortran/decl.cc
>> @@ -3366,6 +3366,7 @@ close_brackets:
>>        else
>>      gfc_error ("Missing right parenthesis at %C");
>>        m = MATCH_ERROR;
>> +      goto no_match;
>>      }
>>    else
>>       /* All tests passed.  */
>> @@ -4716,6 +4717,9 @@ get_kind:
>>        return MATCH_ERROR;
>>      }
>>
>> +  if (m == MATCH_ERROR)
>> +    return MATCH_ERROR;
>> +
> ... can you move this up to the place where m is set?
> OK with that change.

I was afraid that this would regress on the existing testcases
pr91660_[12].f90 that depend on an error message emitted just
before that hunk, but this turned out not to happen.

Adjusted version committed as:
r14-1477-gff8f45d20f9ea6acc99442ad29212d177f58e8fe .

> Thanks
>

Thanks for the review!

Harald


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-01 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 19:05 [PATCH] Fortran: force error on bad KIND specifier [PR88552] Harald Anlauf
2023-06-01 20:33 ` Mikael Morin
2023-06-01 21:11   ` Harald Anlauf

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).