public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/106918] New: Cannot use structure constructor with component allocatable character array of deferred length
@ 2022-09-12 20:51 guez at lmd dot ens.fr
2023-04-08 8:04 ` [Bug fortran/106918] " cvs-commit at gcc dot gnu.org
2023-04-08 9:37 ` pault at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: guez at lmd dot ens.fr @ 2022-09-12 20:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106918
Bug ID: 106918
Summary: Cannot use structure constructor with component
allocatable character array of deferred length
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: guez at lmd dot ens.fr
Target Milestone: ---
gcc version 12.0.1 20220319 (experimental) [master r12-7719-g8ca61ad148f]
(Ubuntu 12-20220319-1ubuntu1)
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
12-20220319-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-OcsLtf/gcc-12-12-20220319/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-OcsLtf/gcc-12-12-20220319/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
GNU Fortran (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Here is a test program:
$ cat test_coord_def.f90
character(len = :), allocatable:: attr_name(:)
type coord_def
character(len = :), allocatable:: attr_name(:)
end type coord_def
type(coord_def) coordinates
attr_name = ["units"]
print *, 'attr_name: "', attr_name, '"'
coordinates = coord_def(attr_name)
print *, 'coordinates%attr_name: "', coordinates%attr_name, '"'
end
The compilation command is:
$ gfortran-12 test_coord_def.f90
There is no compilation message.
The execution fails:
$ ./a.out
attr_name: "units"
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc
Error termination. Backtrace:
#0 0x1538fa556ae0 in ???
#1 0x1538fa557659 in ???
#2 0x1538fa557834 in ???
#3 0x1538fa555fee in ???
#4 0x1538fa7ba355 in ???
#5 0x1538fa7ab1b9 in ???
#6 0x1538fa7b3c00 in ???
#7 0x1538fa7b90ae in ???
#8 0x1538fa7ba105 in ???
#9 0x1538fa7ab8a8 in ???
#10 0x555fac4a76d8 in ???
#11 0x555fac4a7751 in ???
#12 0x1538fa334d8f in __libc_start_call_main
at ../sysdeps/nptl/libc_start_call_main.h:58
#13 0x1538fa334e3f in __libc_start_main_impl
at ../csu/libc-start.c:392
#14 0x555fac4a7114 in ???
#15 0xffffffffffffffff in ???
I think the source code is valid. Note that if I replace the structure
constructor by an equivalent assignment to the component, the problem
disappears:
$ cat test_coord_def.f90
character(len = :), allocatable:: attr_name(:)
type coord_def
character(len = :), allocatable:: attr_name(:)
end type coord_def
type(coord_def) coordinates
attr_name = ["units"]
print *, 'attr_name: "', attr_name, '"'
coordinates%attr_name = attr_name
!!coordinates = coord_def(attr_name)
print *, 'coordinates%attr_name: "', coordinates%attr_name, '"'
end
$ gfortran-12 test_coord_def.f90
$ ./a.out
attr_name: "units"
coordinates%attr_name: "units"
Also, for additional information, there is no problem with ifort 19.1.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug fortran/106918] Cannot use structure constructor with component allocatable character array of deferred length
2022-09-12 20:51 [Bug fortran/106918] New: Cannot use structure constructor with component allocatable character array of deferred length guez at lmd dot ens.fr
@ 2023-04-08 8:04 ` cvs-commit at gcc dot gnu.org
2023-04-08 9:37 ` pault at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-08 8:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106918
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:
https://gcc.gnu.org/g:eac493851f07df98213ecf67a5e9ab41a7babcd2
commit r13-7121-geac493851f07df98213ecf67a5e9ab41a7babcd2
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Sat Apr 8 09:04:13 2023 +0100
Fortran: Fix some of the bugs in associate [PR87477]
2023-04-08 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/87477
* iresolve.cc (gfc_resolve_adjustl, gfc_resolve_adjustr): if
string length is deferred use the string typespec for result.
* resolve.cc (resolve_assoc_var): Handle parentheses around the
target expression.
(resolve_block_construct): Remove unnecessary static decls.
* trans-array.cc (gfc_conv_expr_descriptor): Guard string len
expression in condition. Improve handling of string length and
span, especially for substrings of the descriptor.
(duplicate_allocatable): Make element type more explicit with
'eltype'.
* trans-decl.cc (gfc_get_symbol_decl): Emit a fatal error with
appropriate message instead of ICE if symbol type is unknown.
(gfc_generate_function_code): Set current locus to proc_sym
declared_at.
* trans-expr.cc (gfc_get_expr_charlen): Retain last charlen in
'previous' and use if end expression in substring reference is
null.
(gfc_conv_string_length): Use gfc_conv_expr_descriptor if
'expr_flat' is an array. Add post block to catch deallocation
of temporaries.
(gfc_conv_procedure_call): Assign the parmse string length to
the expression string length, if it is deferred.
(gfc_trans_alloc_subarray_assign): If this is a deferred string
length component, store the string length in the hidden comp.
Update the typespec length accordingly. Generate a new type
spec for the call to gfc_duplicate-allocatable in this case.
* trans-io.cc (gfc_trans_transfer): Scalarize transfer of
deferred character array components.
gcc/testsuite/
PR fortran/87477
* gfortran.dg/associate_47.f90 : Enable substring test.
* gfortran.dg/associate_51.f90 : Update an error message.
* gfortran.dg/goacc/array-with-dt-2.f90 : Add span to
uninitialzed dg-warnings.
PR fortran/85686
PR fortran/88247
PR fortran/91941
PR fortran/92779
PR fortran/93339
PR fortran/93813
PR fortran/100948
PR fortran/102106
* gfortran.dg/associate_60.f90 : New test
PR fortran/98408
* gfortran.dg/pr98408.f90 : New test
PR fortran/105205
* gfortran.dg/pr105205.f90 : New test
PR fortran/106918
* gfortran.dg/pr106918.f90 : New test
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug fortran/106918] Cannot use structure constructor with component allocatable character array of deferred length
2022-09-12 20:51 [Bug fortran/106918] New: Cannot use structure constructor with component allocatable character array of deferred length guez at lmd dot ens.fr
2023-04-08 8:04 ` [Bug fortran/106918] " cvs-commit at gcc dot gnu.org
@ 2023-04-08 9:37 ` pault at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pault at gcc dot gnu.org @ 2023-04-08 9:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106918
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |pault at gcc dot gnu.org
Resolution|--- |FIXED
--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on mainline
Thanks for the report
Paul
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-08 9:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12 20:51 [Bug fortran/106918] New: Cannot use structure constructor with component allocatable character array of deferred length guez at lmd dot ens.fr
2023-04-08 8:04 ` [Bug fortran/106918] " cvs-commit at gcc dot gnu.org
2023-04-08 9:37 ` pault at gcc dot gnu.org
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).