[gcc r14-10362] Fortran: fix for CHARACTER(len=*) dummies with bind(C) [PR115390]
Harald Anlauf
anlauf@gcc.gnu.org
Sun Jun 30 18:26:37 GMT 2024
https://gcc.gnu.org/g:b31e1900fa0cffabb0702962d01ba3fe917fdf69
commit r14-10362-gb31e1900fa0cffabb0702962d01ba3fe917fdf69
Author: Harald Anlauf <anlauf@gmx.de>
Date: Tue Jun 18 21:57:19 2024 +0200
Fortran: fix for CHARACTER(len=*) dummies with bind(C) [PR115390]
gcc/fortran/ChangeLog:
PR fortran/115390
* trans-decl.cc (gfc_conv_cfi_to_gfc): Move derivation of type sizes
for character via gfc_trans_vla_type_sizes to after character length
has been set.
gcc/testsuite/ChangeLog:
PR fortran/115390
* gfortran.dg/bind_c_char_11.f90: New test.
(cherry picked from commit 954f9011c4923b72f42cc6ca8460333e7c7aad98)
Diff:
---
gcc/fortran/trans-decl.cc | 4 +--
gcc/testsuite/gfortran.dg/bind_c_char_11.f90 | 45 ++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 301439baaf5..1a319b27449 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -7056,8 +7056,8 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t *finally,
if (sym->ts.type == BT_CHARACTER
&& !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
{
- gfc_conv_string_length (sym->ts.u.cl, NULL, init);
- gfc_trans_vla_type_sizes (sym, init);
+ gfc_conv_string_length (sym->ts.u.cl, NULL, &block);
+ gfc_trans_vla_type_sizes (sym, &block);
}
/* gfc->data = cfi->base_addr - or for scalars: gfc = cfi->base_addr.
diff --git a/gcc/testsuite/gfortran.dg/bind_c_char_11.f90 b/gcc/testsuite/gfortran.dg/bind_c_char_11.f90
new file mode 100644
index 00000000000..5ed8e82853b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/bind_c_char_11.f90
@@ -0,0 +1,45 @@
+! { dg-do compile }
+! { dg-additional-options "-Wuninitialized" }
+!
+! PR fortran/115390 - fixes for CHARACTER(len=*) dummies with bind(C)
+
+module test
+ implicit none
+contains
+ subroutine bar(s,t) bind(c)
+ character(*), intent(in) :: s,t
+ optional :: t
+ call foo(s,t)
+ end
+ subroutine bar1(s,t) bind(c)
+ character(*), intent(in) :: s(:),t(:)
+ optional :: t
+ call foo1(s,t)
+ end
+ subroutine bar4(s,t) bind(c)
+ character(len=*,kind=4), intent(in) :: s,t
+ optional :: t
+ call foo4(s,t)
+ end
+ subroutine bar5(s,t) bind(c)
+ character(len=*,kind=4), intent(in) :: s(:),t(:)
+ optional :: t
+ call foo5(s,t)
+ end
+ subroutine foo(s,t)
+ character(*), intent(in) :: s,t
+ optional :: t
+ end
+ subroutine foo1(s,t)
+ character(*), intent(in) :: s(:),t(:)
+ optional :: t
+ end
+ subroutine foo4(s,t)
+ character(len=*,kind=4), intent(in) :: s,t
+ optional :: t
+ end
+ subroutine foo5(s,t)
+ character(len=*,kind=4), intent(in) :: s(:),t(:)
+ optional :: t
+ end
+end
More information about the Gcc-cvs
mailing list