diff options
author | Fritz O. Reese <fritzoreese@gmail.com> | 2016-11-10 21:57:13 +0000 |
---|---|---|
committer | Fritz Reese <foreese@gcc.gnu.org> | 2016-11-10 21:57:13 +0000 |
commit | 94903212646d0b90a92afc0ca47a348ab92719c1 (patch) | |
tree | 14856b9dbfce8af631a0a5aa61b9970b2bca3a07 /gcc | |
parent | 05b8fcb4d2087c1544ebe3ad128711f12bcff022 (diff) | |
download | gcc-94903212646d0b90a92afc0ca47a348ab92719c1.zip gcc-94903212646d0b90a92afc0ca47a348ab92719c1.tar.gz gcc-94903212646d0b90a92afc0ca47a348ab92719c1.tar.bz2 |
Fix ICE and improve errors for invalid anonymous structure declarations.
PR fortran/78277
* gcc/fortran/decl.c (gfc_match_data_decl): Gracefully handle bad
anonymous structure declarations.
PR fortran/78277
* gcc/testsuite/gfortran.dg/dec_structure_17.f90: New test.
From-SVN: r242058
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/decl.c | 23 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/dec_structure_17.f90 | 27 |
4 files changed, 60 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0872b49..ae8f661 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,11 @@ 2016-11-10 Fritz O. Reese <fritzoreese@gmail.com> + PR fortran/78277 + * gcc/fortran/decl.c (gfc_match_data_decl): Gracefully handle bad + anonymous structure declarations. + +2016-11-10 Fritz O. Reese <fritzoreese@gmail.com> + * decl.c (get_struct_decl, gfc_match_map, gfc_match_union): Fix whitespace. * interface.c (gfc_compare_union_types): Likewise. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 1272f1f..bf6bc24 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -4901,7 +4901,28 @@ ok: } if (!gfc_error_flag_test ()) - gfc_error ("Syntax error in data declaration at %C"); + { + /* An anonymous structure declaration is unambiguous; if we matched one + according to gfc_match_structure_decl, we need to return MATCH_YES + here to avoid confusing the remaining matchers, even if there was an + error during variable_decl. We must flush any such errors. Note this + causes the parser to gracefully continue parsing the remaining input + as a structure body, which likely follows. */ + if (current_ts.type == BT_DERIVED && current_ts.u.derived + && gfc_fl_struct (current_ts.u.derived->attr.flavor)) + { + gfc_error_now ("Syntax error in anonymous structure declaration" + " at %C"); + /* Skip the bad variable_decl and line up for the start of the + structure body. */ + gfc_error_recovery (); + m = MATCH_YES; + goto cleanup; + } + + gfc_error ("Syntax error in data declaration at %C"); + } + m = MATCH_ERROR; gfc_free_data_all (gfc_current_ns); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c82dbf..e16fdde 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-10 Fritz O. Reese <fritzoreese@gmail.com> + + PR fortran/78277 + * gfortran.dg/dec_structure_17.f90: New test. + 2016-11-10 Michael Meissner <meissner@linux.vnet.ibm.com> * gcc.target/powerpc/vsx-qimode.c: New test for QImode, HImode diff --git a/gcc/testsuite/gfortran.dg/dec_structure_17.f90 b/gcc/testsuite/gfortran.dg/dec_structure_17.f90 new file mode 100644 index 0000000..18d3193 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_structure_17.f90 @@ -0,0 +1,27 @@ +! { dg-do compile } +! { dg-options "-fdec-structure" } +! +! PR fortran/78277 +! +! Fix ICE for invalid structure declaration code. +! + +subroutine sub1() + structure /s/ + structure t + integer i + end structure + end structure + record /s/ u + interface + subroutine sub0(u) + structure /s/ + structure t. ! { dg-error "Syntax error in anonymous structure decl" } + integer i + end structure + end structure + record /s/ u + end + end interface + call sub0(u) +end |