public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pault at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/113363] ICE on ASSOCIATE and unlimited polymorphic function
Date: Sun, 14 Jan 2024 08:54:53 +0000 [thread overview]
Message-ID: <bug-113363-4-utU6qz8myX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113363-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113363
--- Comment #1 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #0)
> While discussing a patch for PR89645/99065, the following issue with
> ASSOCIATE and unlimited polymorphic functions was found:
>
> https://gcc.gnu.org/pipermail/fortran/2024-January/060098.html
>
> program p
> implicit none
> class(*), allocatable :: x(:)
> x = foo()
> call prt (x)
> deallocate (x) ! up to here all is fine...
> associate (var => foo()) ! <- crash here
> call prt (var) ! <- or here
> end associate
> contains
> function foo() result(res)
> class(*), allocatable :: res(:)
> res = [42]
> end function foo
> subroutine prt (x)
> class(*), intent(in) :: x(:)
> select type (x)
> type is (integer)
> print *, x
> class default
> stop 99
> end select
> end subroutine prt
> end
>
>
> This ICEs on current trunk for any of the indicated statements.
The associate bit is fixed with a one liner; with the patch applied:
@@ -2295,7 +2305,8 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block
*block)
}
/* Set the stringlength, when needed. */
- if (need_len_assign)
+ if (need_len_assign
+ && !(e->symtree->n.sym->attr.function && UNLIMITED_POLY
(e->symtree->n.sym)))
{
gfc_se se;
gfc_init_se (&se, NULL);
the following gives the output in the comments:
program p
implicit none
class(*), allocatable :: x(:)
allocate(x, source = foo())
call prt (x) ! Wrong output "6 hello e"
deallocate (x)
x = foo()
call prt (x) ! Wrong output "0 "
deallocate (x) !
associate (var => foo()) ! Now OK
call prt (var) ! Now OK - outputs: "6 hello bye "
end associate
contains
function foo() result(res)
class(*), allocatable :: res(:)
res = ["hello ","bye "]
end function foo
subroutine prt (x)
class(*), intent(in) :: x(:)
select type (x)
type is (character(*))
print *, len(x), x
class default
stop 99
end select
end subroutine prt
end
Both allocation with source and assignment are broken :-(
next prev parent reply other threads:[~2024-01-14 8:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 20:31 [Bug fortran/113363] New: " anlauf at gcc dot gnu.org
2024-01-14 8:54 ` pault at gcc dot gnu.org [this message]
2024-01-14 9:22 ` [Bug fortran/113363] " pault at gcc dot gnu.org
2024-01-17 14:46 ` pault at gcc dot gnu.org
2024-04-03 18:56 ` anlauf at gcc dot gnu.org
2024-04-04 6:27 ` pault at gcc dot gnu.org
2024-04-04 19:12 ` anlauf at gcc dot gnu.org
2024-04-06 10:05 ` pault at gcc dot gnu.org
2024-05-07 7:43 ` rguenth at gcc dot gnu.org
2024-05-13 6:27 ` cvs-commit at gcc dot gnu.org
2024-05-13 6:37 ` pault at gcc dot gnu.org
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=bug-113363-4-utU6qz8myX@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@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).