From: Janne Blomqvist Date: Thu, 28 Dec 2017 18:49:12 +0000 (+0200) Subject: PR fortran/83344 Don't set bogus constant value X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=208413c7b4d3a2360ba4864f00ceaf720b4f67c7;p=gcc.git PR fortran/83344 Don't set bogus constant value This patch does not fix PR 83344, but merely fixes an error where we used to set a constant character length value from a non-constant expression, and thus set it to some bogus value. As a result of this, I have commented out part of the associate_22.f90 test which otherwise generates a warning message. Regtested on x86_64-pc-linux-gnu. gcc/fortran/ChangeLog: 2017-12-28 Janne Blomqvist PR fortran/83344 * resolve.c (resolve_assoc_var): Don't set the constant value unless the target is a constant expression. gcc/testsuite/ChangeLog: 2017-12-28 Janne Blomqvist PR fortran/83344 * gfortran.dg/associate_22.f90: Comment out part of test. From-SVN: r256021 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 3f3dc3ee23a..fd4d8a6ae62 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-12-28 Janne Blomqvist + + PR fortran/83344 + * resolve.c (resolve_assoc_var): Don't set the constant value + unless the target is a constant expression. + 2017-12-28 Paul Thomas PR fortran/83567 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index f819b715861..cf75a78d7ba 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -8627,7 +8627,8 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target) if (!sym->ts.u.cl) sym->ts.u.cl = target->ts.u.cl; - if (!sym->ts.u.cl->length && !sym->ts.deferred) + if (!sym->ts.u.cl->length && !sym->ts.deferred + && target->expr_type == EXPR_CONSTANT) sym->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, target->value.character.length); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e69175084c..1e91e7f5480 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,9 +1,14 @@ +2017-12-28 Janne Blomqvist + + PR fortran/83344 + * gfortran.dg/associate_22.f90: Comment out part of test. + 2017-12-28 Paul Thomas PR fortran/83567 * gfortran.dg/pdt_26.f90 : New test. -2017_12_27 Louis Krupp +2017-12-27 Louis Krupp PR fortran/83092 * gfortran.dg/init_char_with_nonchar_ctr.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/associate_22.f90 b/gcc/testsuite/gfortran.dg/associate_22.f90 index 1558992004d..edf59321dd5 100644 --- a/gcc/testsuite/gfortran.dg/associate_22.f90 +++ b/gcc/testsuite/gfortran.dg/associate_22.f90 @@ -24,10 +24,11 @@ program foo end associate ! This failed. - a = trim(s) // 'abc' - associate(w => trim(s) // 'abc') - if (trim(w) /= trim(a)) call abort - end associate + ! This still doesn't work correctly, see PR 83344 +! a = trim(s) // 'abc' +! associate(w => trim(s) // 'abc') +! if (trim(w) /= trim(a)) call abort +! end associate ! This failed. associate(x => trim('abc'))