diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2018-09-17 11:22:27 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2018-09-17 11:22:27 +0000 |
commit | d44235fbe06e52cf670fccc7419a580bfedabec9 (patch) | |
tree | c57268dca7f97e743b78d13dc2c8485eaef52229 /gcc | |
parent | ecfb64f692c561ef16bca0ff17b3d7e9ee14b418 (diff) | |
download | gcc-d44235fbe06e52cf670fccc7419a580bfedabec9.zip gcc-d44235fbe06e52cf670fccc7419a580bfedabec9.tar.gz gcc-d44235fbe06e52cf670fccc7419a580bfedabec9.tar.bz2 |
re PR fortran/64120 ([F03] Wrong handling of allocatable character string)
2018-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/64120
* trans-decl.c (gfc_get_symbol_decl): Flag allocatable, scalar
characters with a variable length expression for deferred init.
(gfc_trans_deferred_vars): Perform the assignment for these
symbols by calling gfc_conv_string_length.
2018-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/64120
* gfortran.dg/allocatable_scalar_14.f90 : New test.
From-SVN: r264365
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/fortran/trans-decl.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/allocatable_scalar_14.f90 | 17 |
4 files changed, 44 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 22435d3..3980146 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,13 @@ 2018-09-17 Paul Thomas <pault@gcc.gnu.org> + PR fortran/64120 + * trans-decl.c (gfc_get_symbol_decl): Flag allocatable, scalar + characters with a variable length expression for deferred init. + (gfc_trans_deferred_vars): Perform the assignment for these + symbols by calling gfc_conv_string_length. + +2018-09-17 Paul Thomas <pault@gcc.gnu.org> + PR fortran/85954 * resolve.c (resolve_assoc_var): If the target expression is a deferred charlen dummy and the associate name shares the diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index e54d098..06066eb 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1745,6 +1745,13 @@ gfc_get_symbol_decl (gfc_symbol * sym) && !(sym->attr.use_assoc && !intrinsic_array_parameter))) gfc_defer_symbol_init (sym); + if (sym->ts.type == BT_CHARACTER + && sym->attr.allocatable + && !sym->attr.dimension + && sym->ts.u.cl && sym->ts.u.cl->length + && sym->ts.u.cl->length->expr_type == EXPR_VARIABLE) + gfc_defer_symbol_init (sym); + /* Associate names can use the hidden string length variable of their associated target. */ if (sym->ts.type == BT_CHARACTER @@ -4603,6 +4610,13 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) gfc_set_backend_locus (&sym->declared_at); gfc_start_block (&init); + if (sym->ts.type == BT_CHARACTER + && sym->attr.allocatable + && !sym->attr.dimension + && sym->ts.u.cl && sym->ts.u.cl->length + && sym->ts.u.cl->length->expr_type == EXPR_VARIABLE) + gfc_conv_string_length (sym->ts.u.cl, NULL, &init); + if (!sym->attr.pointer) { /* Nullify and automatic deallocation of allocatable diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bcb851a..bf186057d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-17 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/64120 + * gfortran.dg/allocatable_scalar_14.f90 : New test. + 2018-09-17 Richard Biener <rguenther@suse.de> PR tree-optimization/87301 diff --git a/gcc/testsuite/gfortran.dg/allocatable_scalar_14.f90 b/gcc/testsuite/gfortran.dg/allocatable_scalar_14.f90 new file mode 100644 index 0000000..23f6bbf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocatable_scalar_14.f90 @@ -0,0 +1,17 @@ +! { dg-do run } +! +! Test the fix for PR64120 in which the initialisation of the +! string length of 's' was not being done. +! +! Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> +! + call g(1) + call g(2) +contains + subroutine g(x) + integer :: x + character(len=x), allocatable :: s + allocate(s) + if (len(s) .ne. x) stop x + end subroutine +end |