This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/82774] Structure constructor and deferred type parameter character component
- From: "kargl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 30 Oct 2017 21:15:29 +0000
- Subject: [Bug fortran/82774] Structure constructor and deferred type parameter character component
- Auto-submitted: auto-generated
- References: <bug-82774-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82774
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P4
Known to fail| |8.0
--- Comment #1 from kargl at gcc dot gnu.org ---
A thread in c.l.f has exposed a problem with a structure
constructor and a deferred character components. Consider
the code
% a.f90
program main
implicit none
type stuff
character(:), allocatable :: key
end type stuff
type(stuff) nonsense, total
nonsense = stuff('Xe')
total = stuff(nonsense%key)
if (nonsense%key /= total%key) call abort
if (len(total%key) /= 2) call abort
end program main
% gfcx -o z a.f90 && ./z
Abort (core dumped)
If the line
total = stuff(nonsense%key)
is replaced by
total = stuff(trim(nonsense%key))
then the program compiles and runs correctly.
Thus, the reference to nonsense%key is not
being probably evaluated in the original
program. This can be seen in the dump file.
{
struct stuff stuff.0;
struct stuff D.3538;
stuff.0.key = (character(kind=1)[1:0] *) __builtin_malloc (2);
stuff.0._key_length = 2;
(void) __builtin_memcpy ((void *) stuff.0.key, (void *) "Xe", 2);
D.3538 = nonsense;
nonsense = stuff.0;
if (D.3538.key != 0B)
{
__builtin_free ((void *) D.3538.key);
D.3538.key = 0B;
}
}
{
struct stuff stuff.1;
struct stuff D.3540;
stuff.1.key = (character(kind=1)[1:0] *) __builtin_malloc (1);
stuff.1._key_length = 0;
(void) __builtin_memcpy ((void *) stuff.1.key, (void *) nonsense.key,
(unsigned long) nonsense._key_length);
D.3540 = total;
total = stuff.1;
if (D.3540.key != 0B)
{
__builtin_free ((void *) D.3540.key);
D.3540.key = 0B;
}
}
stuff.1 is clearly wrong.