public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: Harald Anlauf <anlauf@gmx.de>, fortran <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR fortran/50549 - should detect different type parameters in structure constructors
Date: Mon, 28 Mar 2022 12:05:30 +0200	[thread overview]
Message-ID: <5a7fa9f6-7155-9dc6-d847-e44ccccb447a@codesourcery.com> (raw)
In-Reply-To: <trinity-e33ad297-0829-4d0c-b715-502f50f62f5b-1648410290770@3c-app-gmx-bap05>

Hi Harald,

On 27.03.22 21:44, Harald Anlauf via Fortran wrote:
> when assigning character pointers, we have a check for same length,
> which however does not trigger for character pointers within a
> structure constructor.
>
> The attached patch extends the character checks slightly to fix
> this loophole.  I've verified that NAG and Crayftn behave similarly,
> while Intel does not detect the length difference.
>
> Regtested on x86_64-pc-linux-gnu.
>
> OK for mainline?

Thanks for the patch! LGTM and I think GCC 12 is still okay.

However, I have a nit:

> --- a/gcc/fortran/resolve.cc
> +++ b/gcc/fortran/resolve.cc
> @@ -1375,11 +1375,22 @@ resolve_structure_cons (gfc_expr *expr, int init)
> ...
> +           long len_a, len_b;
> +           len_a = mpz_get_si (comp->ts.u.cl->length->value.integer);
> +           len_b = mpz_get_si (cons->expr->ts.u.cl->length->value.integer);
> +           gfc_error ("Unequal character lengths (%ld/%ld) for pointer "
> +                      "component %qs in constructor at %L",
> +                      len_a, len_b, comp->name, &cons->expr->where);

'long' might be int32_t instead of int64_t (e.g. on Windows, I think both
MinGW32 and MinGW64, but I am not quite sure). Thus, I wonder whether it
makes more sense to use:

   HOST_WIDE_INT, gfc_mpz_get_hwi() and '%wd'

I note that '%wd' (and '%lld') is only supported since last August
(commit https://gcc.gnu.org/r12-3044-g1b507b1e3c5 ), but now that it is,
I think we should use it at places where the value can be larger than INT_MAX.

I think at some point, we should also check the rest of the code and
change those mpz_get_si to gfc_mpz_get_hwi which can exceed INT_MAX.
Likewise, some of the %ld/%lu or %lld/%llu code should be also converted to %wd/%wu.

Tobias

PS: For using HWI with 'sprintf' instead of diagnostic's error/warning,
HOST_WIDE_INT_PRINT_DEC exists and has to be used.

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

  reply	other threads:[~2022-03-28 10:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-27 19:44 Harald Anlauf
2022-03-28 10:05 ` Tobias Burnus [this message]
2022-03-28 20:03   ` Harald Anlauf
2022-03-28 20:03     ` Harald Anlauf
2022-03-28 21:08     ` Harald Anlauf
2022-03-28 21:08       ` Harald Anlauf
2022-03-28 21:52       ` Joseph Myers
2022-03-29  7:14     ` Tobias Burnus
2022-03-29 18:48       ` Harald Anlauf
2022-03-29 18:48         ` Harald Anlauf

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=5a7fa9f6-7155-9dc6-d847-e44ccccb447a@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).