public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Morin <morin-mikael@orange.fr>
To: Tobias Burnus <tobias@codesourcery.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>
Subject: Re: [Patch] Fortran: Fix reallocation on assignment for kind=4 strings [PR107508]
Date: Sun, 6 Nov 2022 21:32:05 +0100	[thread overview]
Message-ID: <2163ce95-3e4f-b887-eb35-50134bc381de@orange.fr> (raw)
In-Reply-To: <dee92d68-139c-9a2d-325e-2c3f402291e8@codesourcery.com>

Hello,

Le 05/11/2022 à 23:28, Tobias Burnus a écrit :
> Prior to the attached patch, there is a problem with realloc on assignment
> with kind=4 characters as the string length was compared with the byte 
> size,
> which was always true.
> 
(...)

> OK for mainline?
> 
The trans-array.c part looks good.
A couple of nits for the trans-expr.cc part:

> diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
> index e7b9211f17e..44c373cc495 100644
> --- a/gcc/fortran/trans-expr.cc
> +++ b/gcc/fortran/trans-expr.cc
> @@ -11236,10 +11236,10 @@ alloc_scalar_allocatable_for_assignment (stmtblock_t *block,
>  
>    if (expr1->ts.type == BT_CHARACTER && expr1->ts.deferred)
>      {
> -      /* Use the rhs string length and the lhs element size.  */
> -      size = string_length;
> -      tmp = TREE_TYPE (gfc_typenode_for_spec (&expr1->ts));
> -      tmp = TYPE_SIZE_UNIT (tmp);
> +      /* Use the rhs string length and the lhs element size. Note that 'size' is
> +	 used below for the string-length comparison, only.  */
> +      size = string_length,
s/,/;/ ?
> +      tmp = TYPE_SIZE_UNIT (gfc_get_char_type (expr2->ts.kind));
Here you are using the rhs element size, which contradicts the comment, 
so there is certainly something to fix here (either the comment or the 
code).

>        size_in_bytes = fold_build2_loc (input_location, MULT_EXPR,
>  				       TREE_TYPE (tmp), tmp,
>  				       fold_convert (TREE_TYPE (tmp), size));

As for the testcase, do you keep the code commented on purpose?
Can some of it be removed or uncommented?

Mikael

  parent reply	other threads:[~2022-11-06 20:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-05 22:28 Tobias Burnus
2022-11-05 23:45 ` Bernhard Reutner-Fischer
2022-11-06 20:32 ` Mikael Morin [this message]
2022-11-06 22:15   ` Tobias Burnus

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=2163ce95-3e4f-b887-eb35-50134bc381de@orange.fr \
    --to=morin-mikael@orange.fr \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias@codesourcery.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).