From: Paul Thomas Date: Sun, 27 Nov 2016 19:00:00 +0000 (+0000) Subject: re PR fortran/78474 ([F08] gfortran accepts invalid submodule syntax) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e578b767c509911cdef2325ad144fa3dacfb7f12;p=gcc.git re PR fortran/78474 ([F08] gfortran accepts invalid submodule syntax) 2016-11-27 Paul Thomas PR fortran/78474 * module.c (gfc_match_submodule): If there is more than one colon, it is a syntax error. PR fortran/78331 * module.c (gfc_use_module): If an smod file does not exist it is either because the module does not have a module procedure interface or there is an error in the module. 2016-11-27 Paul Thomas PR fortran/78474 * gfortran.dg/submodule_22.f08: New test. PR fortran/78331 * gfortran.dg/submodule_21.f08: New test. From-SVN: r242900 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f01373c2f6b..b6e82d75ed5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2016-11-27 Paul Thomas + + PR fortran/78474 + * module.c (gfc_match_submodule): If there is more than one + colon, it is a syntax error. + + PR fortran/78331 + * module.c (gfc_use_module): If an smod file does not exist it + is either because the module does not have a module procedure + interface or there is an error in the module. + 2016-11-25 Janne Blomqvist * intrinsic.texi: Fix ptrdiff_t typo in ISO_C_BINDING constants diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 4116db8ecad..e727adebc99 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -740,6 +740,7 @@ gfc_match_submodule (void) match m; char name[GFC_MAX_SYMBOL_LEN + 1]; gfc_use_list *use_list; + bool seen_colon = false; if (!gfc_notify_std (GFC_STD_F2008, "SUBMODULE declaration at %C")) return MATCH_ERROR; @@ -772,7 +773,7 @@ gfc_match_submodule (void) } else { - module_list = use_list; + module_list = use_list; use_list->module_name = gfc_get_string (name); use_list->submodule_name = use_list->module_name; } @@ -780,8 +781,11 @@ gfc_match_submodule (void) if (gfc_match_char (')') == MATCH_YES) break; - if (gfc_match_char (':') != MATCH_YES) + if (gfc_match_char (':') != MATCH_YES + || seen_colon) goto syntax; + + seen_colon = true; } m = gfc_match (" %s%t", &gfc_new_block); @@ -6926,8 +6930,17 @@ gfc_use_module (gfc_use_list *module) } if (module_fp == NULL) - gfc_fatal_error ("Can't open module file %qs for reading at %C: %s", - filename, xstrerror (errno)); + { + if (gfc_state_stack->state != COMP_SUBMODULE + && module->submodule_name == NULL) + gfc_fatal_error ("Can't open module file %qs for reading at %C: %s", + filename, xstrerror (errno)); + else + gfc_fatal_error ("Module file %qs has not been generated, either " + "because the module does not contain a MODULE " + "PROCEDURE or there is an error in the module.", + filename); + } /* Check that we haven't already USEd an intrinsic module with the same name. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f6433bbd53..b1f4c61508a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2016-11-27 Paul Thomas + + PR fortran/78474 + * gfortran.dg/submodule_22.f08: New test. + + PR fortran/78331 + * gfortran.dg/submodule_21.f08: New test. + 2016-11-27 John David Anglin * g++.dg/torture/pr65655.C: Use dg-timeout-factor 2. diff --git a/gcc/testsuite/gfortran.dg/submodule_21.f08 b/gcc/testsuite/gfortran.dg/submodule_21.f08 new file mode 100644 index 00000000000..c96acb2e856 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_21.f08 @@ -0,0 +1,19 @@ +! { dg-do compile } +! +! Test the fix for PR78331. +! +! Reported on https://groups.google.com/forum/#!topic/comp.lang.fortran/NFCF9brKksg +! +MODULE MainModule +END MODULE MainModule + +SUBMODULE (MainModule) MySub1 + IMPLICIT NONE + INTEGER, PARAMETER :: a = 17 +END SUBMODULE MySub1 + +PROGRAM MyProg + USE MainModule + WRITE(*,*) a +END PROGRAM MyProg +! { dg-excess-errors "does not contain a MODULE PROCEDURE" } diff --git a/gcc/testsuite/gfortran.dg/submodule_22.f08 b/gcc/testsuite/gfortran.dg/submodule_22.f08 new file mode 100644 index 00000000000..8ff5421c77e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_22.f08 @@ -0,0 +1,47 @@ +! { dg-do compile } +! +! Test the fix for PR78474. +! +! Contributed by Nicholas Brearly +! +module mtop + implicit none + real :: r + interface + module subroutine sub1() + end subroutine + end interface + interface + module subroutine sub2() + end subroutine + end interface + interface + module subroutine sub3() + end subroutine + end interface +end module mtop + +submodule (mtop) submod + implicit none + real :: s +contains + module subroutine sub1 + r = 0.0 + end subroutine sub1 +end + +submodule (mtop:submod) subsubmod +contains + module subroutine sub2 + r = 1.0 + s = 1.0 + end subroutine sub2 +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 +end