aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2016-11-27 19:00:00 +0000
committerPaul Thomas <pault@gcc.gnu.org>2016-11-27 19:00:00 +0000
commite578b767c509911cdef2325ad144fa3dacfb7f12 (patch)
treef5e81c1cd4cacf52af813f2ef61df3045b430cc7 /gcc
parentae829c9503f7859d426d4b99d27c1a6bdf4ee2c1 (diff)
downloadgcc-e578b767c509911cdef2325ad144fa3dacfb7f12.zip
gcc-e578b767c509911cdef2325ad144fa3dacfb7f12.tar.gz
gcc-e578b767c509911cdef2325ad144fa3dacfb7f12.tar.bz2
re PR fortran/78474 ([F08] gfortran accepts invalid submodule syntax)
2016-11-27 Paul Thomas <pault@gcc.gnu.org> 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 <pault@gcc.gnu.org> PR fortran/78474 * gfortran.dg/submodule_22.f08: New test. PR fortran/78331 * gfortran.dg/submodule_21.f08: New test. From-SVN: r242900
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog11
-rw-r--r--gcc/fortran/module.c21
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gfortran.dg/submodule_21.f0819
-rw-r--r--gcc/testsuite/gfortran.dg/submodule_22.f0847
5 files changed, 102 insertions, 4 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index f01373c..b6e82d7 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,14 @@
+2016-11-27 Paul Thomas <pault@gcc.gnu.org>
+
+ 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 <jb@gcc.gnu.org>
* intrinsic.texi: Fix ptrdiff_t typo in ISO_C_BINDING constants
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index 4116db8..e727ade 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 8f6433b..b1f4c61 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2016-11-27 Paul Thomas <pault@gcc.gnu.org>
+
+ 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 <danglin@gcc.gnu.org>
* 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 0000000..c96acb2
--- /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 0000000..8ff5421
--- /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 <nick.brealey@cobham.com>
+!
+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