From: Sandra Loosemore <sandra@codesourcery.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
Date: Thu, 6 Jan 2022 13:11:28 -0700 [thread overview]
Message-ID: <e8d7da83-00ab-8fb0-eb87-915c52c4e85c@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 335 bytes --]
This patch fixes an ICE introduced with the recent-ish rewrite to inline
the SIZE intrinsic, using a helper function to do the bulk of the work
in producing the expansion. It turns out to be a simple think-o type
mistake in the wrapper around the helper rather than anything deeply
wrong with the logic.
OK to check in?
-Sandra
[-- Attachment #2: pr103898.patch --]
[-- Type: text/x-patch, Size: 2215 bytes --]
commit 0e5b74440572f988dd96a6e9c33c11b59323d6cf
Author: Sandra Loosemore <sandra@codesourcery.com>
Date: Thu Jan 6 11:23:18 2022 -0800
Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
This patch fixes a think-o in the code that triggered an ICE
in the test case.
2021-01-06 Sandra Loosemore <sandra@codesourcery.com>
gcc/fortran/
* trans-intrinsic.c (gfc_conv_intrinsic_size): Make size_var
actually be a variable and fix surrounding code.
gcc/testsuite/
* gfortran.dg/pr103898.f90: New test.
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 41252c9..aae34b0 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -8006,10 +8006,14 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr)
cond = gfc_evaluate_now (cond, &se->pre);
/* 'block2' contains the arg2 absent case, 'block' the arg2 present
case; size_var can be used in both blocks. */
- tree size_var = gfc_tree_array_size (&block2, arg1, e, NULL_TREE);
+ tree size_var = gfc_create_var (TREE_TYPE (size), "size");
tmp = fold_build2_loc (input_location, MODIFY_EXPR,
TREE_TYPE (size_var), size_var, size);
gfc_add_expr_to_block (&block, tmp);
+ size = gfc_tree_array_size (&block2, arg1, e, NULL_TREE);
+ tmp = fold_build2_loc (input_location, MODIFY_EXPR,
+ TREE_TYPE (size_var), size_var, size);
+ gfc_add_expr_to_block (&block2, tmp);
tmp = build3_v (COND_EXPR, cond, gfc_finish_block (&block),
gfc_finish_block (&block2));
gfc_add_expr_to_block (&se->pre, tmp);
diff --git a/gcc/testsuite/gfortran.dg/pr103898.f90 b/gcc/testsuite/gfortran.dg/pr103898.f90
new file mode 100644
index 0000000..6b4bb30
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103898.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+
+! This test used to ICE during gimplification (PR103898).
+
+Module g
+contains
+ function mysize(array, dim)
+ integer :: mysize
+ integer, dimension(:), intent(in) :: array
+ integer, optional, intent(in) :: dim
+ if (present(dim)) then
+ mysize = size(array, dim=dim)
+ endif
+ end function mysize
+end module
next reply other threads:[~2022-01-06 20:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 20:11 Sandra Loosemore [this message]
2022-01-06 21:16 ` Harald Anlauf
2022-01-06 21:16 ` 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=e8d7da83-00ab-8fb0-eb87-915c52c4e85c@codesourcery.com \
--to=sandra@codesourcery.com \
--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).