From: Mikael Morin <morin-mikael@orange.fr>
To: Harald Anlauf <anlauf@gmx.de>, fortran <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR fortran/104573 - ICE in resolve_structure_cons, at fortran/resolve.cc:1299
Date: Mon, 28 Feb 2022 22:32:20 +0100 [thread overview]
Message-ID: <15b8291c-e95c-ce61-2739-a4032905a393@orange.fr> (raw)
In-Reply-To: <trinity-447b5aad-73a7-403c-9cb3-1dac18f13b6c-1645046402715@3c-app-gmx-bap59>
Le 16/02/2022 à 22:20, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
>
> while we detect invalid uses of type(*), we may run into other issues
> later when the declared variable is used, leading to an ICE due to a
> NULL pointer dereference. This is demonstrated by Gerhard's testcase.
>
> Steve and I came to rather similar fixes, see PR. Mine is attached.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> Thanks,
> Harald
>
> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
> index 266e41e25b1..2fa1acdbd6d 100644
> --- a/gcc/fortran/resolve.cc
> +++ b/gcc/fortran/resolve.cc
> @@ -1288,15 +1288,17 @@ resolve_structure_cons (gfc_expr *expr, int init)
> }
> }
>
> - cons = gfc_constructor_first (expr->value.constructor);
> -
> /* A constructor may have references if it is the result of substituting a
> parameter variable. In this case we just pull out the component we
> want. */
> if (expr->ref)
> comp = expr->ref->u.c.sym->components;
> - else
> + else if (expr->ts.u.derived)
> comp = expr->ts.u.derived->components;
These unprotected union accesses always make me nervous.
I have tried (hard) to exhibit a case not fixed by your patch,
and I have found the case below that almost qualifies, except that there
is an ICE before anything can happen.
With a minor tweak to prevent the ICE, the problem does appear.
program p
type t
integer :: a
end type
character(3), parameter :: x = t(2)
character(3), parameter :: y = x
print *, y
end
In that case the character length information occupies the same space as
a derived type symbol; the else-if condition evaluates to true, and
everything breaks from there.
So please use a condition on expr->ts.type instead.
I think the relevant values associated with ts->u.derived are
BT_DERIVED, BT_CLASS and BT_UNION.
OK with that change.
Thanks, and sorry for the time I took before looking at it.
next prev parent reply other threads:[~2022-02-28 21:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 21:20 Harald Anlauf
2022-02-23 22:35 ` *Ping* " Harald Anlauf
2022-02-28 21:32 ` Mikael Morin [this message]
2022-02-28 21:38 ` Mikael Morin
2022-03-01 22:18 ` [PATCH, v2] " Harald Anlauf
2022-03-01 22:18 ` Harald Anlauf
2022-03-02 11:37 ` Mikael Morin
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=15b8291c-e95c-ce61-2739-a4032905a393@orange.fr \
--to=morin-mikael@orange.fr \
--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).