* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
@ 2019-04-20 16:57 Dominique d'Humières
2019-04-20 17:21 ` Steve Kargl
0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2019-04-20 16:57 UTC (permalink / raw)
To: Steve Kargl; +Cc: gfortran, gcc-patches
Hi Steve,
The changes in gfortran.dg/submodule_22.f08 look weird:
(1) is the error in the CONTAINS of a SUBMODULE invalid?
From
* decl.c (in_module_or_interface): New function to check that the
current state is in a module, submodule, or interface.
it should not, should it?
(2) left over?
+
+found outside of a module
TIA
Dominique
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-20 16:57 [PATCH] PR fortran/90166 -- check F2018:C1547 Dominique d'Humières
@ 2019-04-20 17:21 ` Steve Kargl
2019-04-20 19:51 ` Steve Kargl
0 siblings, 1 reply; 8+ messages in thread
From: Steve Kargl @ 2019-04-20 17:21 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gfortran, gcc-patches
On Sat, Apr 20, 2019 at 05:38:34PM +0200, Dominique d'Humières wrote:
>
> The changes in gfortran.dg/submodule_22.f08 look weird:
> (1) is the error in the CONTAINS of a SUBMODULE invalid?
> From
>
> * decl.c (in_module_or_interface): New function to check that the
> current state is in a module, submodule, or interface.
>
> it should not, should it?
>
> (2) left over?
> +
> +found outside of a module
>
It's a sequence of run-on errors. The first statement in
the original code is rejected with a syntax error. When
that happenrs gfc_current_state() is not COMP_MODULE,
COMP_SUBMODULE, or COMP_INTERFENCE. The next line has
the MODULE prefix, and the new check finds that it
occurs outside of MODULE, SUBMODULE, and INTERFERENCE,
so a new error occurs. The remaining errors are then
found to be bogus assignments. My conclusion, if the
first error is fixed, then the run-on errors don't
happen.
If you rather fix the problems with '! dg-options "-fmax-errors=1"'
I'm fine with that.
--
Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-20 17:21 ` Steve Kargl
@ 2019-04-20 19:51 ` Steve Kargl
2019-04-20 20:30 ` Dominique d'Humières
0 siblings, 1 reply; 8+ messages in thread
From: Steve Kargl @ 2019-04-20 19:51 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gfortran, gcc-patches
On Sat, Apr 20, 2019 at 09:57:34AM -0700, Steve Kargl wrote:
> On Sat, Apr 20, 2019 at 05:38:34PM +0200, Dominique d'Humières wrote:
> >
> > The changes in gfortran.dg/submodule_22.f08 look weird:
> > (1) is the error in the CONTAINS of a SUBMODULE invalid?
> > From
> >
> > * decl.c (in_module_or_interface): New function to check that the
> > current state is in a module, submodule, or interface.
> >
> > it should not, should it?
> >
> > (2) left over?
> > +
> > +found outside of a module
> >
>
> It's a sequence of run-on errors. The first statement in
> the original code is rejected with a syntax error. When
> that happenrs gfc_current_state() is not COMP_MODULE,
> COMP_SUBMODULE, or COMP_INTERFENCE. The next line has
> the MODULE prefix, and the new check finds that it
> occurs outside of MODULE, SUBMODULE, and INTERFERENCE,
> so a new error occurs. The remaining errors are then
> found to be bogus assignments. My conclusion, if the
> first error is fixed, then the run-on errors don't
> happen.
>
> If you rather fix the problems with '! dg-options "-fmax-errors=1"'
> I'm fine with that.
>
Just to follow up. If you use a debugger, one finds
(gdb) b decl.c:6130
(gdb) c
Continuing.
/safe/sgk/gcc/gccx/gcc/testsuite/gfortran.dg/submodule_22.f08:41:23:
41 | submodule (mtop:submod:subsubmod) subsubsubmod ! { dg-error "Syntax error in SUBMODULE statement" }
| 1
Error: Syntax error in SUBMODULE statement at (1)
This is the original error. Note it is a syntax error. gfortran
does nothing with this statement
(gdb) c
we reach the point where the new error will be issued.
(gdb) p gfc_state_stack->state
$2 = COMP_CONTAINS
This is the CONTAINS in the submodule.
(gdb) p gfc_state_stack->previous->state
$3 = COMP_PROGRAM
This state fine here, because the syntax rejects the submodule
statement. So, the code looks like (from memory...)
[program main implicitly included here]
contains
module subroutine foo
x = 2
y = 3
end submodule
The module prefix cannot appear in the subroutine statement. The
new error rejects it. So, now you have 2 assignments in after a
contains statement. The program now looks like
contains
x = 2
y = 3
end submodule
Well, you cannot do an assignment, so two additional error messages
are emitted. So, now we come to a program of the form
[program main implicitly included here]
end submodule
gfortran is expecting an END [PROGRAM] statement.
Is this clear or do you want me to withdrawal the patch?
--
Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-20 19:51 ` Steve Kargl
@ 2019-04-20 20:30 ` Dominique d'Humières
2019-04-21 18:03 ` Steve Kargl
0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2019-04-20 20:30 UTC (permalink / raw)
To: Steve Kargl; +Cc: gfortran, gcc-patches
OK I missed the previous error. However I am still puzzled by (2):
+
+found outside of a module
Dominique
> Le 20 avr. 2019 à 21:18, Steve Kargl <sgk@troutmask.apl.washington.edu> a écrit :
>
> On Sat, Apr 20, 2019 at 09:57:34AM -0700, Steve Kargl wrote:
>> On Sat, Apr 20, 2019 at 05:38:34PM +0200, Dominique d'Humières wrote:
>>>
>>> The changes in gfortran.dg/submodule_22.f08 look weird:
>>> (1) is the error in the CONTAINS of a SUBMODULE invalid?
>>> From
>>>
>>> * decl.c (in_module_or_interface): New function to check that the
>>> current state is in a module, submodule, or interface.
>>>
>>> it should not, should it?
>>>
>>> (2) left over?
>>> +
>>> +found outside of a module
>>>
>>
>> It's a sequence of run-on errors. The first statement in
>> the original code is rejected with a syntax error. When
>> that happenrs gfc_current_state() is not COMP_MODULE,
>> COMP_SUBMODULE, or COMP_INTERFENCE. The next line has
>> the MODULE prefix, and the new check finds that it
>> occurs outside of MODULE, SUBMODULE, and INTERFERENCE,
>> so a new error occurs. The remaining errors are then
>> found to be bogus assignments. My conclusion, if the
>> first error is fixed, then the run-on errors don't
>> happen.
>>
>> If you rather fix the problems with '! dg-options "-fmax-errors=1"'
>> I'm fine with that.
>>
>
> Just to follow up. If you use a debugger, one finds
>
> (gdb) b decl.c:6130
> (gdb) c
> Continuing.
> /safe/sgk/gcc/gccx/gcc/testsuite/gfortran.dg/submodule_22.f08:41:23:
>
> 41 | submodule (mtop:submod:subsubmod) subsubsubmod ! { dg-error "Syntax error in SUBMODULE statement" }
> | 1
> Error: Syntax error in SUBMODULE statement at (1)
>
> This is the original error. Note it is a syntax error. gfortran
> does nothing with this statement
>
> (gdb) c
>
> we reach the point where the new error will be issued.
>
> (gdb) p gfc_state_stack->state
> $2 = COMP_CONTAINS
>
> This is the CONTAINS in the submodule.
>
> (gdb) p gfc_state_stack->previous->state
> $3 = COMP_PROGRAM
>
> This state fine here, because the syntax rejects the submodule
> statement. So, the code looks like (from memory...)
>
> [program main implicitly included here]
> contains
> module subroutine foo
> x = 2
> y = 3
> end submodule
>
> The module prefix cannot appear in the subroutine statement. The
> new error rejects it. So, now you have 2 assignments in after a
> contains statement. The program now looks like
>
> contains
> x = 2
> y = 3
> end submodule
>
> Well, you cannot do an assignment, so two additional error messages
> are emitted. So, now we come to a program of the form
>
>
> [program main implicitly included here]
> end submodule
>
> gfortran is expecting an END [PROGRAM] statement.
>
> Is this clear or do you want me to withdrawal the patch?
>
> --
> Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-20 20:30 ` Dominique d'Humières
@ 2019-04-21 18:03 ` Steve Kargl
2019-04-22 13:53 ` Dominique d'Humières
0 siblings, 1 reply; 8+ messages in thread
From: Steve Kargl @ 2019-04-21 18:03 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gfortran, gcc-patches
On Sat, Apr 20, 2019 at 09:51:11PM +0200, Dominique d'Humières wrote:
> OK I missed the previous error. However I am still puzzled by (2):
>
> +
> +found outside of a module
>
Why are you puzzled? Did you read the patch? The
entire error message is
+ gfc_error ("MODULE prefix at %C found outside of a module, "
+ "submodule, or interface");
In
program foo
contains
module subroutine foo
end subroutine foo
end program foo
The "MODULE prefix" attached to "subroutine foo" is
found outside of a module, a submodule, or interface.
--
Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-21 18:03 ` Steve Kargl
@ 2019-04-22 13:53 ` Dominique d'Humières
0 siblings, 0 replies; 8+ messages in thread
From: Dominique d'Humières @ 2019-04-22 13:53 UTC (permalink / raw)
To: Steve Kargl; +Cc: gfortran, gcc-patches
> Le 21 avr. 2019 à 18:02, Steve Kargl <sgk@troutmask.apl.washington.edu> a écrit :
>
> On Sat, Apr 20, 2019 at 09:51:11PM +0200, Dominique d'Humières wrote:
>> OK I missed the previous error. However I am still puzzled by (2):
>>
>> +
>> +found outside of a module
>>
>
> Why are you puzzled? Did you read the patch?
I read
Index: gcc/testsuite/gfortran.dg/submodule_22.f08
===================================================================
--- gcc/testsuite/gfortran.dg/submodule_22.f08 (revision 270181)
+++ gcc/testsuite/gfortran.dg/submodule_22.f08 (working copy)
@@ -40,8 +40,10 @@ end
submodule (mtop:submod:subsubmod) subsubsubmod ! { dg-error "Syntax error in SUBMODULE statement" }
contains
- module subroutine sub3
- r = 2.0
- s = 2.0
- end subroutine sub3
+ module subroutine sub3 ! { dg-error "found outside of a module" }
+ r = 2.0 ! { dg-error "Unexpected assignment" }
+ s = 2.0 ! { dg-error "Unexpected assignment" }
+ end subroutine sub3 ! { dg-error "Expecting END PROGRAM statement" }
end
+
+found outside of a module
^ I cannot relate this to any dejagnu command
Dominique
> The
> entire error message is
>
> + gfc_error ("MODULE prefix at %C found outside of a module, "
> + "submodule, or interface");
>
> In
>
> program foo
> contains
> module subroutine foo
> end subroutine foo
> end program foo
>
> The "MODULE prefix" attached to "subroutine foo" is
> found outside of a module, a submodule, or interface.
>
> --
> Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] PR fortran/90166 -- check F2018:C1547
@ 2019-04-19 22:12 Steve Kargl
2019-04-20 18:37 ` Paul Richard Thomas
0 siblings, 1 reply; 8+ messages in thread
From: Steve Kargl @ 2019-04-19 22:12 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 656 bytes --]
The attached patch fixes PR fortran/91066. The original
code was feeding a nonsense string of tokens to the
assembler causing it to toss its cookies. It turns out
that gfortran was not enforcing the constraint C1547
from Fortran 2018. The attached patch now performs
that check. Regression tested on x86_64-*-freebsd.
OK to commit?
2019-04-19 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/90166
* decl.c (in_module_or_interface): New function to check that the
current state is in a module, submodule, or interface.
(gfc_match_prefix): Use it.
PR fortran/90166
* gfortran.dg/submodule_22.f08: Add additional dg-error comments.
--
Steve
[-- Attachment #2: pr90166.diff --]
[-- Type: text/x-diff, Size: 2188 bytes --]
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 270181)
+++ gcc/fortran/decl.c (working copy)
@@ -6070,7 +6070,29 @@ cleanup:
return m;
}
+static bool
+in_module_or_interface(void)
+{
+ if (gfc_current_state () == COMP_MODULE
+ || gfc_current_state () == COMP_SUBMODULE
+ || gfc_current_state () == COMP_INTERFACE)
+ return true;
+ if (gfc_state_stack->state == COMP_CONTAINS
+ || gfc_state_stack->state == COMP_FUNCTION
+ || gfc_state_stack->state == COMP_SUBROUTINE)
+ {
+ gfc_state_data *p;
+ for (p = gfc_state_stack->previous; p ; p = p->previous)
+ {
+ if (p->state == COMP_MODULE || p->state == COMP_SUBMODULE
+ || p->state == COMP_INTERFACE)
+ return true;
+ }
+ }
+ return false;
+}
+
/* Match a prefix associated with a function or subroutine
declaration. If the typespec pointer is nonnull, then a typespec
can be matched. Note that if nothing matches, MATCH_YES is
@@ -6102,6 +6124,13 @@ gfc_match_prefix (gfc_typespec *ts)
{
if (!gfc_notify_std (GFC_STD_F2008, "MODULE prefix at %C"))
goto error;
+
+ if (!in_module_or_interface ())
+ {
+ gfc_error ("MODULE prefix at %C found outside of a module, "
+ "submodule, or INTERFACE");
+ goto error;
+ }
current_attr.module_procedure = 1;
found_prefix = true;
Index: gcc/testsuite/gfortran.dg/submodule_22.f08
===================================================================
--- gcc/testsuite/gfortran.dg/submodule_22.f08 (revision 270181)
+++ gcc/testsuite/gfortran.dg/submodule_22.f08 (working copy)
@@ -40,8 +40,10 @@ end
submodule (mtop:submod:subsubmod) subsubsubmod ! { dg-error "Syntax error in SUBMODULE statement" }
contains
- module subroutine sub3
- r = 2.0
- s = 2.0
- end subroutine sub3
+ module subroutine sub3 ! { dg-error "found outside of a module" }
+ r = 2.0 ! { dg-error "Unexpected assignment" }
+ s = 2.0 ! { dg-error "Unexpected assignment" }
+ end subroutine sub3 ! { dg-error "Expecting END PROGRAM statement" }
end
+
+found outside of a module
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] PR fortran/90166 -- check F2018:C1547
2019-04-19 22:12 Steve Kargl
@ 2019-04-20 18:37 ` Paul Richard Thomas
0 siblings, 0 replies; 8+ messages in thread
From: Paul Richard Thomas @ 2019-04-20 18:37 UTC (permalink / raw)
To: Steve Kargl; +Cc: fortran, gcc-patches
It looks good to me, modulo Dominique's query. OK for trunk (note from
Richi - still aiming for zero P1 bugs so you're good to go).
Thanks
Paul
On Fri, 19 Apr 2019 at 22:44, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
>
> The attached patch fixes PR fortran/91066. The original
> code was feeding a nonsense string of tokens to the
> assembler causing it to toss its cookies. It turns out
> that gfortran was not enforcing the constraint C1547
> from Fortran 2018. The attached patch now performs
> that check. Regression tested on x86_64-*-freebsd.
> OK to commit?
>
> 2019-04-19 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/90166
> * decl.c (in_module_or_interface): New function to check that the
> current state is in a module, submodule, or interface.
> (gfc_match_prefix): Use it.
>
> PR fortran/90166
> * gfortran.dg/submodule_22.f08: Add additional dg-error comments.
>
> --
> Steve
--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-04-22 10:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-20 16:57 [PATCH] PR fortran/90166 -- check F2018:C1547 Dominique d'Humières
2019-04-20 17:21 ` Steve Kargl
2019-04-20 19:51 ` Steve Kargl
2019-04-20 20:30 ` Dominique d'Humières
2019-04-21 18:03 ` Steve Kargl
2019-04-22 13:53 ` Dominique d'Humières
-- strict thread matches above, loose matches on Subject: below --
2019-04-19 22:12 Steve Kargl
2019-04-20 18:37 ` Paul Richard Thomas
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).