From: Sandra Loosemore Date: Thu, 6 Jan 2022 19:23:18 +0000 (-0800) Subject: Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55385f12f604fe242030f0a8fb057598c0f187a6;p=test_jj.git 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 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 --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