From: Tobias Burnus <burnus@net-b.de>
To: Paul Richard Thomas <paul.richard.thomas@gmail.com>
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR56008 (and PR47517) [F03] wrong code with lhs-realloc on assignment with derived types having allocatable components
Date: Wed, 23 Jan 2013 10:06:00 -0000 [thread overview]
Message-ID: <50FFB61B.3060008@net-b.de> (raw)
In-Reply-To: <CAGkQGi+bX8=w354dmtfD5ECm=ZXA5xi3q12sjg-Z9mpxW_=UUA@mail.gmail.com>
Paul Richard Thomas wrote:
> *************** gfc_alloc_allocatable_for_assignment (gf
> *** 8224,8229 ****
> --- 8250,8262 ----
> desc, tmp);
> tmp = gfc_conv_descriptor_dtype (desc);
> gfc_add_modify (&alloc_block, tmp, gfc_get_dtype (TREE_TYPE (desc)));
> + if ((expr1->ts.type == BT_DERIVED)
> + && expr1->ts.u.derived->attr.alloc_comp)
> + {
> + tmp = gfc_nullify_alloc_comp (expr1->ts.u.derived, desc,
> + expr1->rank);
> + gfc_add_expr_to_block (&alloc_block, tmp);
> + }
> alloc_expr = gfc_finish_block (&alloc_block);
When glancing at the patch, I wondered whether it would be better to use
CALLOC instead of MALLOC and avoid the nullification:
/* Malloc expression. */
gfc_init_block (&alloc_block);
tmp = build_call_expr_loc (input_location,
builtin_decl_explicit (BUILT_IN_MALLOC),
1, size2);
On the other hand, the nullification is probably still required for
REALLOC. If so, the question is whether CALLOC + nullify in the realloc
branch - or malloc + nullify after the realloc/malloc branches is
better. Hence, your version is probably fine.
Sorry for not yet reviewing your patch.
Tobias
PS: Regarding "allocatable" and "memory leak": PR55603 has as similar
issue. For scalars, gfortran never frees allocatable function results;
that's independent of the LHS (allocatable, pointer, neither). Thus, if
you are in the mood of fixing those kind of bugs Â… (Actually, I am not
even sure whether that's restricted to allocation, it might also occur
with expressions like "a = f() + 5". Untested.)
next prev parent reply other threads:[~2013-01-23 10:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-22 22:40 Paul Richard Thomas
2013-01-23 10:06 ` Tobias Burnus [this message]
2013-01-28 20:56 ` Paul Richard Thomas
2013-01-28 21:18 ` Thomas Koenig
2013-02-04 22:35 ` Paul Richard Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50FFB61B.3060008@net-b.de \
--to=burnus@net-b.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=paul.richard.thomas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).