From d6a5de161587f701089fdafada742cf275ccd7f8 Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Sun, 3 Mar 2013 17:52:02 +0000 Subject: [PATCH] re PR fortran/54730 (ICE in gfc_typenode_for_spec, at fortran/trans-types.c:1066) fortran/ PR fortran/54730 * array.c (gfc_match_array_constructor): Set a checkpoint before matching a typespec. Drop it on success, restore it otherwise. testsuite/ PR fortran/54730 * gfortran.dg/array_constructor_42.f90: New test. From-SVN: r196416 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/array.c | 17 +++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/array_constructor_42.f90 | 22 +++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_constructor_42.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c9b0ca6ce571..c12dd9822193 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2013-03-03 Mikael Morin + + PR fortran/54730 + * array.c (gfc_match_array_constructor): Set a checkpoint before + matching a typespec. Drop it on success, restore it otherwise. + 2013-03-03 Mikael Morin PR fortran/54730 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 6787c05de8d2..6ee292c2a768 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1046,6 +1046,7 @@ match gfc_match_array_constructor (gfc_expr **result) { gfc_constructor_base head, new_cons; + gfc_undo_change_set changed_syms; gfc_expr *expr; gfc_typespec ts; locus where; @@ -1074,6 +1075,7 @@ gfc_match_array_constructor (gfc_expr **result) /* Try to match an optional "type-spec ::" */ gfc_clear_ts (&ts); + gfc_new_undo_checkpoint (changed_syms); if (gfc_match_decl_type_spec (&ts, 0) == MATCH_YES) { seen_ts = (gfc_match (" ::") == MATCH_YES); @@ -1082,19 +1084,28 @@ gfc_match_array_constructor (gfc_expr **result) { if (gfc_notify_std (GFC_STD_F2003, "Array constructor " "including type specification at %C") == FAILURE) - goto cleanup; + { + gfc_restore_last_undo_checkpoint (); + goto cleanup; + } if (ts.deferred) { gfc_error ("Type-spec at %L cannot contain a deferred " "type parameter", &where); + gfc_restore_last_undo_checkpoint (); goto cleanup; } } } - if (! seen_ts) - gfc_current_locus = where; + if (seen_ts) + gfc_drop_last_undo_checkpoint (); + else + { + gfc_restore_last_undo_checkpoint (); + gfc_current_locus = where; + } if (gfc_match (end_delim) == MATCH_YES) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 112b6ae37ec8..c34cd0f4a74a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-03-03 Mikael Morin + + PR fortran/54730 + * gfortran.dg/array_constructor_42.f90: New test. + 2013-03-02 Paolo Carlini PR c++/52688 diff --git a/gcc/testsuite/gfortran.dg/array_constructor_42.f90 b/gcc/testsuite/gfortran.dg/array_constructor_42.f90 new file mode 100644 index 000000000000..676247cdd5d9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_42.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! +! PR fortran/54730 +! A symbol 'a' was created while attempting to parse a typespec in the array +! constructor. That (invalid) symbol was kept until translation stage +! where it was leading to an ICE. +! +! Original testcase from Paul Kapinos +! + + subroutine s + implicit none + intrinsic :: real + real :: vec(1:2) + vec = (/ real(a = 1), 1. /) + end subroutine s + + program main + implicit none + intrinsic :: real + print *,(/ real(a = 1) /) + end -- 2.47.3