Fortran: Fix character(len=cst) dummies with bind(C) [PR102885]
PR fortran/102885 gcc/fortran/ChangeLog: * trans-decl.c (gfc_conv_cfi_to_gfc): Properly handle nonconstant character lenghts. gcc/testsuite/ChangeLog: * gfortran.dg/lto/bind-c-char_0.f90: New test.
This commit is contained in:
parent
6b8b255755
commit
a31a3d0421
2 changed files with 56 additions and 0 deletions
|
@ -6837,6 +6837,13 @@ gfc_conv_cfi_to_gfc (stmtblock_t *init, stmtblock_t *finally,
|
|||
gfc_add_modify (&block, sym->ts.u.cl->backend_decl, tmp);
|
||||
}
|
||||
|
||||
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->data = cfi->base_addr - or for scalars: gfc = cfi->base_addr.
|
||||
assumed-size/explicit-size arrays end up here for character(len=*)
|
||||
only. */
|
||||
|
|
49
gcc/testsuite/gfortran.dg/lto/bind-c-char_0.f90
Normal file
49
gcc/testsuite/gfortran.dg/lto/bind-c-char_0.f90
Normal file
|
@ -0,0 +1,49 @@
|
|||
! { dg-lto-do link }
|
||||
! { dg-lto-options {{ -O0 -flto }} }
|
||||
!
|
||||
! PR fortran/102885
|
||||
|
||||
module m
|
||||
use iso_c_binding, only: c_char
|
||||
implicit none (type, external)
|
||||
|
||||
contains
|
||||
|
||||
! Assumed-shape array, nonallocatable/nonpointer
|
||||
|
||||
subroutine ar3 (xn, n) bind(C)
|
||||
integer :: n
|
||||
character(len=n) :: xn(..)
|
||||
if (size(xn) /= 6) stop
|
||||
if (len(xn) /= 5) stop
|
||||
select rank(xn)
|
||||
rank(1)
|
||||
xn = ['FDGhf', &
|
||||
'hdrhg', &
|
||||
'fDgFl', &
|
||||
'DFHs3', &
|
||||
'4a54G', &
|
||||
'hSs6k']
|
||||
rank default
|
||||
stop
|
||||
end select
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
program main
|
||||
use m
|
||||
implicit none (type, external)
|
||||
character(kind=c_char, len=5) :: str5a6(6)
|
||||
|
||||
! assumed rank - with array descriptor
|
||||
|
||||
str5a6 = ['DDGhf', &
|
||||
'hdrh$', &
|
||||
'fDGSl', &
|
||||
'DFHs3', &
|
||||
'43grG', &
|
||||
'hFG$k']
|
||||
call ar3 (str5a6, 5)
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue