public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8947] Fortran: Set the length of an allocatable character
@ 2024-02-13 4:51 Jerry DeLisle
0 siblings, 0 replies; only message in thread
From: Jerry DeLisle @ 2024-02-13 4:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6caec7d9ec37e60e718a12934c85bac9c12757ac
commit r14-8947-g6caec7d9ec37e60e718a12934c85bac9c12757ac
Author: Steve Kargl <kargl@gcc.gnu.org>
Date: Mon Feb 12 20:41:02 2024 -0800
Fortran: Set the length of an allocatable character
PR fortran/113883
gcc/fortran/ChangeLog:
* trans-array.cc (gfc_trans_deferred_array): Set length to zero,
avoiding extraneous diagnostics.
gcc/testsuite/ChangeLog:
* gfortran.dg/allocatable_length.f90: New test.
Diff:
---
gcc/fortran/trans-array.cc | 3 +++
gcc/testsuite/gfortran.dg/allocatable_length.f90 | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 1e0d698a9497..2181990aa04a 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11531,6 +11531,9 @@ gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
if (sym->ts.type == BT_CHARACTER
&& !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
{
+ if (sym->ts.deferred && !sym->ts.u.cl->length)
+ gfc_add_modify (&init, sym->ts.u.cl->backend_decl,
+ build_zero_cst (TREE_TYPE (sym->ts.u.cl->backend_decl)));
gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
gfc_trans_vla_type_sizes (sym, &init);
diff --git a/gcc/testsuite/gfortran.dg/allocatable_length.f90 b/gcc/testsuite/gfortran.dg/allocatable_length.f90
new file mode 100644
index 000000000000..e8b638fac880
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/allocatable_length.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-Werror -Wall" }
+module foo
+ contains
+ subroutine bar
+ character(len=:), allocatable :: s(:)
+ call bah(s)
+ end subroutine bar
+end module foo
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-13 4:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 4:51 [gcc r14-8947] Fortran: Set the length of an allocatable character Jerry DeLisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).