From b64400b66aaa7c8a38c087d8261e0dbae759b482 Mon Sep 17 00:00:00 2001 From: kargl Date: Sun, 8 Nov 2015 17:25:16 +0000 Subject: [PATCH] 2015-11-08 Steven G. Kargl PR fortran/68224 * array.c (match_array_element_spec): Check of invalid NULL(). While here, fix nearby comments. 2015-11-08 Steven G. Kargl PR fortran/68224 * gfortran.dg/pr68224.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229955 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/array.c | 24 +++++++++++++++++++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr68224.f90 | 10 ++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr68224.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index ce3d7d03410..21534d28628 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-11-08 Steven G. Kargl + + PR fortran/68224 + * array.c (match_array_element_spec): Check of invalid NULL(). + While here, fix nearby comments. + 2015-11-08 Paul Thomas PR fortran/68196 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 2083044774f..0b676af551e 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -147,9 +147,9 @@ matched: } -/* Match an array reference, whether it is the whole array or a - particular elements or a section. If init is set, the reference has - to consist of init expressions. */ +/* Match an array reference, whether it is the whole array or particular + elements or a section. If init is set, the reference has to consist + of init expressions. */ match gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init, @@ -422,6 +422,13 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; + if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN + && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0) + { + gfc_error ("Expecting a scalar INTEGER expression at %C"); + return AS_UNKNOWN; + } + if (gfc_match_char (':') == MATCH_NO) { *lower = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1); @@ -442,13 +449,20 @@ match_array_element_spec (gfc_array_spec *as) if (!gfc_expr_check_typed (*upper, gfc_current_ns, false)) return AS_UNKNOWN; + if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN + && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0) + { + gfc_error ("Expecting a scalar INTEGER expression at %C"); + return AS_UNKNOWN; + } + return AS_EXPLICIT; } /* Matches an array specification, incidentally figuring out what sort - it is. Match either a normal array specification, or a coarray spec - or both. Optionally allow [:] for coarrays. */ + it is. Match either a normal array specification, or a coarray spec + or both. Optionally allow [:] for coarrays. */ match gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2801c946fe7..f11872fd636 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-08 Steven G. Kargl + + PR fortran/68224 + * gfortran.dg/pr68224.f90: New test. + 2015-11-08 Paul Thomas PR fortran/68196 diff --git a/gcc/testsuite/gfortran.dg/pr68224.f90 b/gcc/testsuite/gfortran.dg/pr68224.f90 new file mode 100644 index 00000000000..a5962bb8661 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr68224.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/68224 +! Original code contribute by Gerhard Steinmetz +! +! +program p + integer, parameter :: a(null()) = [1, 2] ! { dg-error "scalar INTEGER expression" } + integer, parameter :: b(null():*) = [1, 2] ! { dg-error "scalar INTEGER expression" } + integer, parameter :: c(1:null()) = [1, 2] ! { dg-error "scalar INTEGER expression" } +end program p -- 2.11.4.GIT