From 38acc41d6d761b635123eefa93743b9139debbae Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Mon, 20 Apr 2020 13:21:38 +0200 Subject: [PATCH] PR 91800 - reject Hollerith constants as type initializer. 2020-04-20 Steve Kargl Thomas Koenig PR fortran/91800 * decl.c (variable_decl): Reject Hollerith constants as type initializer. 2020-04-20 Steve Kargl Thomas Koenig PR fortran/91800 * gfortran.dg/hollerith_9.f90: New test. --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/decl.c | 9 +++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gfortran.dg/hollerith_9.f90 | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/hollerith_9.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 336ce49090e..2671c1aa381 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2020-04-20 Steve Kargl + Thomas Koenig + + PR fortran/91800 + * decl.c (variable_decl): Reject Hollerith constants as type + initializer. + 2020-04-19 Thomas Koenig PR fortran/93500 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index b3ed63c97cc..d650407da41 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2903,6 +2903,15 @@ variable_decl (int elem) goto cleanup; } + if (gfc_current_state () == COMP_DERIVED + && initializer && initializer->ts.type == BT_HOLLERITH) + { + gfc_error ("Initialization of structure component with a HOLLERITH " + "constant at %L is not allowed", &initializer->where); + m = MATCH_ERROR; + goto cleanup; + } + if (gfc_current_state () == COMP_DERIVED && gfc_current_block ()->attr.pdt_template) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 27ab5478d29..f8dba65ff9f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-04-20 Steve Kargl + Thomas Koenig + + PR fortran/91800 + * gfortran.dg/hollerith_9.f90: New test. + 2020-04-19 David Edelsohn * g++.dg/debug/dwarf2/pr85550.C: Skip AIX. diff --git a/gcc/testsuite/gfortran.dg/hollerith_9.f90 b/gcc/testsuite/gfortran.dg/hollerith_9.f90 new file mode 100644 index 00000000000..cfa16209e93 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/hollerith_9.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR 91800 - this used to cause an ICE. +module m + type t(n) ! { dg-error "does not have a component corresponding to parameter" } + integer, len :: n = 4habcd ! { dg-error "Initialization of structure component with a HOLLERITH constant" } + end type +end -- 2.30.2