------- Comment #6 from kargl at gcc dot gnu dot org 2009-09-27 17:20 -------
(In reply to comment #0)
> The example below shows that besides the fact that declared as INTENT(OUT) the
> component 'n' is not initialized per default the second time.
It's not initialized on the first call to INIT(), either.
Form -fdump-tree-original
init (struct container_t & restrict container)
{
if (container != 0)
{
if (container->a.data != 0B)
{
__builtin_free ((void *) container->a.data);
}
container->a.data = 0B;
}
}
There is no assignment here. If we look at MAIN
MAIN__ ()
{
static struct container_t container = {.n=4242};
static void init (struct container_t & restrict);
static void dump (struct container_t & restrict);
container.a.data = 0B;
{
struct container_t D.1317;
struct container_t container_t.1;
container_t.1.n = 4242;
container_t.1.a.data = 0B;
D.1317 = container;
container = container_t.1;
if (D.1317.a.data != 0B)
{
__builtin_free ((void *) D.1317.a.data);
}
D.1317.a.data = 0B;
}
init (&container);
dump (&container);
container.n = 1;
dump (&container);
init (&container);
we see the n = 4242 (I changed the value to 4242) from the
original declaration statement.
On a side note, if
integer, dimension(:), allocatable :: a
is replaced with
integer, dimension(:), pointer :: a
we get
REMOVE:kargl[272] ./z
value = 4242
value = 1
value = 4242
and -fdump-tree-original shows
init (struct container_t & restrict container)
{
if (container != 0)
{
{
struct container_t D.1311;
struct container_t container_t.1;
container_t.1.n = 4242;
D.1311 = container_t.1;
*container = D.1311;
}
}
}
I suspect that this has been broken since allocatable component
were introduced into gfortran.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479