From 357ad64f1cc374a7d63f0ac509d398a628cb56cc Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Fri, 13 Jun 2008 15:04:26 +0200 Subject: [PATCH] re PR fortran/36476 (ICE: len=* CHARACTER array with separate PARAMETER statement) 2008-06-13 Tobias Burnus PR fortran/36476 * decl.c (do_parm): Handle init expression for len=*. 2008-06-13 Tobias Burnus PR fortran/36476 * gfortran.dg/parameter_array_init_4.f90: New. From-SVN: r136754 --- gcc/fortran/ChangeLog | 5 ++ gcc/fortran/decl.c | 21 ++++++- gcc/testsuite/ChangeLog | 5 ++ .../gfortran.dg/parameter_array_init_4.f90 | 55 +++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/parameter_array_init_4.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e42da2f1e91..4a6b07a7692 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2008-06-13 Tobias Burnus + + PR fortran/36476 + * decl.c (do_parm): Handle init expression for len=*. + 2008-06-12 Tobias Burnus PR fortran/36462 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index c4ef7e7004d..a1c7d5aa44e 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -5820,10 +5820,27 @@ do_parm (void) && sym->ts.cl->length != NULL && sym->ts.cl->length->expr_type == EXPR_CONSTANT && init->expr_type == EXPR_CONSTANT - && init->ts.type == BT_CHARACTER - && init->ts.kind == 1) + && init->ts.type == BT_CHARACTER) gfc_set_constant_character_len ( mpz_get_si (sym->ts.cl->length->value.integer), init, false); + else if (sym->ts.type == BT_CHARACTER && sym->ts.cl != NULL + && sym->ts.cl->length == NULL) + { + int clen; + if (init->expr_type == EXPR_CONSTANT) + { + clen = init->value.character.length; + sym->ts.cl->length = gfc_int_expr (clen); + } + else if (init->expr_type == EXPR_ARRAY) + { + gfc_expr *p = init->value.constructor->expr; + clen = p->value.character.length; + sym->ts.cl->length = gfc_int_expr (clen); + } + else if (init->ts.cl && init->ts.cl->length) + sym->ts.cl->length = gfc_copy_expr (sym->value->ts.cl->length); + } sym->value = init; return MATCH_YES; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ae25ac0723e..333db9a73ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-06-13 Tobias Burnus + + PR fortran/36476 + * gfortran.dg/parameter_array_init_4.f90: New. + 2008-06-13 Eric Botcazou * gcc.c-torture/compile/20080613-1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/parameter_array_init_4.f90 b/gcc/testsuite/gfortran.dg/parameter_array_init_4.f90 new file mode 100644 index 00000000000..5bdcb3723b1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_array_init_4.f90 @@ -0,0 +1,55 @@ +! { dg-do run } +! PR fortran/36476 +! +IMPLICIT NONE +CHARACTER (len=*) MY_STRING(1:3), my_string_s +PARAMETER ( MY_STRING = (/ "A" , "B", "C" /) ) +PARAMETER ( MY_STRING_S = "AB C" ) +character(len=*), parameter :: str(2) = [ 'Ac','cc'] +character(len=*), parameter :: str_s = 'Acc' + +CHARACTER (kind=1,len=*) MY_STRING1(1:3), my_string_s1 +PARAMETER ( MY_STRING1 = (/ "A" , "B", "C" /) ) +PARAMETER ( MY_STRING_S1 = "AB C" ) +character(kind=1,len=*), parameter :: str1(2) = [ 1_'Ac',1_'cc'] +character(kind=1,len=*), parameter :: str_s1 = 'Acc' + +CHARACTER (kind=4,len=*) MY_STRING4(1:3), my_string_s4 +PARAMETER ( MY_STRING4 = (/ "A" , "B", "C" /) ) +PARAMETER ( MY_STRING_S4 = "AB C" ) +character(kind=4,len=*), parameter :: str4(2) = [ 1_'Ac',1_'cc'] +character(kind=4,len=*), parameter :: str_s4 = 'Acc' + +if(len(MY_STRING) /= 1) call abort() +if( MY_STRING(1) /= "A" & + .or.MY_STRING(2) /= "B" & + .or.MY_STRING(3) /= "C") call abort() +if(len(MY_STRING_s) /= 4) call abort() +if(MY_STRING_S /= "AB C") call abort() +if(len(str) /= 2) call abort() +if(str(1) /= "Ac" .or. str(2) /= "cc") call abort() +if(len(str_s) /= 3) call abort() +if(str_s /= 'Acc') call abort() + +if(len(MY_STRING1) /= 1) call abort() +if( MY_STRING1(1) /= 1_"A" & + .or.MY_STRING1(2) /= 1_"B" & + .or.MY_STRING1(3) /= 1_"C") call abort() +if(len(MY_STRING_s1) /= 4) call abort() +if(MY_STRING_S1 /= 1_"AB C") call abort() +if(len(str1) /= 2) call abort() +if(str1(1) /= 1_"Ac" .or. str1(2) /= 1_"cc") call abort() +if(len(str_s1) /= 3) call abort() +if(str_s1 /= 1_'Acc') call abort() + +if(len(MY_STRING4) /= 1) call abort() +if( MY_STRING4(1) /= 4_"A" & + .or.MY_STRING4(2) /= 4_"B" & + .or.MY_STRING4(3) /= 4_"C") call abort() +if(len(MY_STRING_s4) /= 4) call abort() +if(MY_STRING_S4 /= 4_"AB C") call abort() +if(len(str4) /= 2) call abort() +if(str4(1) /= 4_"Ac" .or. str4(2) /= 4_"cc") call abort() +if(len(str_s4) /= 3) call abort() +if(str_s4 /= 4_'Acc') call abort() +end -- 2.30.2