diff options
author | Fritz Reese <fritzoreese@gmail.com> | 2018-07-16 18:24:50 +0000 |
---|---|---|
committer | Fritz Reese <foreese@gcc.gnu.org> | 2018-07-16 18:24:50 +0000 |
commit | e11449d15bda808658b71a0d6643192f0fc43947 (patch) | |
tree | 6b4306e60445587b53dc304533c606f4e4dbd509 /gcc | |
parent | 835e529de2dc75d9c051a178863ae68d8bf1d684 (diff) | |
download | gcc-e11449d15bda808658b71a0d6643192f0fc43947.zip gcc-e11449d15bda808658b71a0d6643192f0fc43947.tar.gz gcc-e11449d15bda808658b71a0d6643192f0fc43947.tar.bz2 |
Fix handling of invalid assumed-shape/size arrays in legacy initializer lists.
2018-07-16 Fritz Reese <fritzoreese@gmail.com>
Fix handling of invalid assumed-shape/size arrays in legacy initializer
lists.
gcc/fortran/ChangeLog:
PR fortran/83184
* decl.c (match_old_style_init): Initialize locus of variable expr when
creating a data variable.
(match_clist_expr): Verify array is explicit shape/size before
attempting to allocate constant array constructor.
gcc/testsuite/ChangeLog:
PR fortran/83184
* gfortran.dg/assumed_rank_14.f90: New testcase.
* gfortran.dg/assumed_rank_15.f90: New testcase.
* gfortran.dg/dec_structure_8.f90: Update error messages.
* gfortran.dg/dec_structure_23.f90: Update error messages.
From-SVN: r262744
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/fortran/decl.c | 63 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/assumed_rank_14.f90 | 11 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/assumed_rank_15.f90 | 11 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/dec_structure_23.f90 | 6 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/dec_structure_8.f90 | 6 |
7 files changed, 80 insertions, 33 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 23781ae..b8c60f5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,13 @@ 2018-07-16 Fritz Reese <fritzoreese@gmail.com> + PR fortran/83184 + * decl.c (match_old_style_init): Initialize locus of variable expr when + creating a data variable. + (match_clist_expr): Verify array is explicit shape/size before + attempting to allocate constant array constructor. + +2018-07-16 Fritz Reese <fritzoreese@gmail.com> + PR fortran/86417 * module.c (mio_component): Set component->loc when loading from module. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 09541da..1384bc7 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -534,6 +534,7 @@ match_old_style_init (const char *name) newdata = gfc_get_data (); newdata->var = gfc_get_data_variable (); newdata->var->expr = gfc_get_variable_expr (st); + newdata->var->expr->where = sym->declared_at; newdata->where = gfc_current_locus; /* Match initial value list. This also eats the terminal '/'. */ @@ -659,7 +660,7 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) { gfc_constructor_base array_head = NULL; gfc_expr *expr = NULL; - match m; + match m = MATCH_ERROR; locus where; mpz_t repeat, cons_size, as_size; bool scalar; @@ -667,18 +668,27 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) gcc_assert (ts); - mpz_init_set_ui (repeat, 0); - scalar = !as || !as->rank; - /* We have already matched '/' - now look for a constant list, as with top_val_list from decl.c, but append the result to an array. */ if (gfc_match ("/") == MATCH_YES) { gfc_error ("Empty old style initializer list at %C"); - goto cleanup; + return MATCH_ERROR; } where = gfc_current_locus; + scalar = !as || !as->rank; + + if (!scalar && !spec_size (as, &as_size)) + { + gfc_error ("Array in initializer list at %L must have an explicit shape", + as->type == AS_EXPLICIT ? &as->upper[0]->where : &where); + /* Nothing to cleanup yet. */ + return MATCH_ERROR; + } + + mpz_init_set_ui (repeat, 0); + for (;;) { m = match_data_constant (&expr); @@ -708,7 +718,10 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) m = match_data_constant (&expr); if (m == MATCH_NO) - gfc_error ("Expected data constant after repeat spec at %C"); + { + m = MATCH_ERROR; + gfc_error ("Expected data constant after repeat spec at %C"); + } if (m != MATCH_YES) goto cleanup; } @@ -751,6 +764,9 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) goto syntax; } + /* If we break early from here out, we encountered an error. */ + m = MATCH_ERROR; + /* Set up expr as an array constructor. */ if (!scalar) { @@ -763,25 +779,13 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) /* Validate sizes. We built expr ourselves, so cons_size will be constant (we fail above for non-constant expressions). - We still need to verify that the array-spec has constant size. */ - cmp = 0; + We still need to verify that the sizes match. */ gcc_assert (gfc_array_size (expr, &cons_size)); - if (!spec_size (as, &as_size)) - { - gfc_error ("Expected constant array-spec in initializer list at %L", - as->type == AS_EXPLICIT ? &as->upper[0]->where : &where); - cmp = -1; - } - else - { - /* Make sure the specs are of the same size. */ - cmp = mpz_cmp (cons_size, as_size); - if (cmp < 0) - gfc_error ("Not enough elements in array initializer at %C"); - else if (cmp > 0) - gfc_error ("Too many elements in array initializer at %C"); - mpz_clear (as_size); - } + cmp = mpz_cmp (cons_size, as_size); + if (cmp < 0) + gfc_error ("Not enough elements in array initializer at %C"); + else if (cmp > 0) + gfc_error ("Too many elements in array initializer at %C"); mpz_clear (cons_size); if (cmp) goto cleanup; @@ -796,10 +800,11 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) expr->ts.u.cl->length_from_typespec = 1; *result = expr; - mpz_clear (repeat); - return MATCH_YES; + m = MATCH_YES; + goto done; syntax: + m = MATCH_ERROR; gfc_error ("Syntax error in old style initializer list at %C"); cleanup: @@ -807,8 +812,12 @@ cleanup: expr->value.constructor = NULL; gfc_free_expr (expr); gfc_constructor_free (array_head); + +done: mpz_clear (repeat); - return MATCH_ERROR; + if (!scalar) + mpz_clear (as_size); + return m; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 854d28e..75cdf50 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-07-16 Fritz Reese <fritzoreese@gmail.com> + + PR fortran/83184 + * gfortran.dg/assumed_rank_14.f90: New testcase. + * gfortran.dg/assumed_rank_15.f90: New testcase. + * gfortran.dg/dec_structure_8.f90: Update error messages. + * gfortran.dg/dec_structure_23.f90: Update error messages. + 2018-07-16 Bernd Edlinger <bernd.edlinger@hotmail.de> PR middle-end/86528 diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_14.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_14.f90 new file mode 100644 index 0000000..18271f9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/assumed_rank_14.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-options "-std=legacy" } +! +! PR fortran/83184 +! + +integer n1(..) /1/ +! { dg-error "Assumed-rank array.*must be a dummy argument" "" { target *-*-* } 7 } +! { dg-error "Assumed-rank variable.*actual argument" "" { target *-*-* } 7 } + +end diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_15.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_15.f90 new file mode 100644 index 0000000..efeb4a5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/assumed_rank_15.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! { dg-options "-fdec-structure" } +! +! PR fortran/83184 +! + +structure /s/ + integer n(..) /1/ ! { dg-error "must have an explicit shape" } +end structure + +end diff --git a/gcc/testsuite/gfortran.dg/dec_structure_23.f90 b/gcc/testsuite/gfortran.dg/dec_structure_23.f90 index 78db344..d79ecc7 100644 --- a/gcc/testsuite/gfortran.dg/dec_structure_23.f90 +++ b/gcc/testsuite/gfortran.dg/dec_structure_23.f90 @@ -13,8 +13,8 @@ program p integer :: nn real :: rr structure /s/ - integer x(n) /1/ ! { dg-error "array with nonconstant bounds" } - integer xx(nn) /1/ ! { dg-error "array with nonconstant bounds" } - integer xxx(rr) /1.0/ ! { dg-error "array with nonconstant bounds" } + integer x(n) /1/ ! { dg-error "must have an explicit shape" } + integer xx(nn) /1/ ! { dg-error "must have an explicit shape" } + integer xxx(rr) /1.0/ ! { dg-error "must have an explicit shape" } end structure end diff --git a/gcc/testsuite/gfortran.dg/dec_structure_8.f90 b/gcc/testsuite/gfortran.dg/dec_structure_8.f90 index 160b92a..f84bf15 100644 --- a/gcc/testsuite/gfortran.dg/dec_structure_8.f90 +++ b/gcc/testsuite/gfortran.dg/dec_structure_8.f90 @@ -6,7 +6,7 @@ ! Old-style (clist) initialization integer,parameter :: as = 3 -structure /t1/ +structure /t1/ ! { dg-error "Type definition.*T1" } integer*1 a /300_2/ ! { dg-error "Arithmetic overflow" } integer b // ! { dg-error "Empty old style initializer list" } integer c /2*3/ ! { dg-error "Repeat spec invalid in scalar" } @@ -44,14 +44,14 @@ record /t1/ ! { dg-error "Invalid character in name" } structure /t2/ ENTRY here ! { dg-error "ENTRY statement.*cannot appear" } - integer a + integer a ! { dg-error "Component.*already declared" } integer a ! { dg-error "Component.*already declared" } structure $z ! { dg-error "Invalid character in name" } structure // ! { dg-error "Invalid character in name" } structure // x ! { dg-error "Invalid character in name" } structure /t3/ ! { dg-error "Invalid character in name" } structure /t3/ x,$y ! { dg-error "Invalid character in name" } - structure /t4/ y + structure /t4/ y ! { dg-error "Type definition.*T4" } integer i, j, k end structure structure /t4/ z ! { dg-error "Type definition.*T4" } |