public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6336] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
@ 2022-01-07 1:35 Sandra Loosemore
0 siblings, 0 replies; only message in thread
From: Sandra Loosemore @ 2022-01-07 1:35 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:55385f12f604fe242030f0a8fb057598c0f187a6
commit r12-6336-g55385f12f604fe242030f0a8fb057598c0f187a6
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>
PR fortran/103898
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:
---
gcc/fortran/trans-intrinsic.c | 6 +++++-
gcc/testsuite/gfortran.dg/pr103898.f90 | 15 +++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 41252c9ae2c..aae34b06948 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 00000000000..6b4bb30e10a
--- /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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-07 1:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 1:35 [gcc r12-6336] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] Sandra Loosemore
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).