diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a396418118d..6f2ba754726 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-09-13 Steven G. Kargl + + PR fortran/91566 + * simplify.c (gfc_simplify_merge): Need to simplify expression + after insertation of parenthesis. + 2019-09-13 Bernd Edlinger PR fortran/91716 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 023eedb749c..3d2fc0d956f 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4780,8 +4780,13 @@ gfc_simplify_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask) gfc_constructor *tsource_ctor, *fsource_ctor, *mask_ctor; if (mask->expr_type == EXPR_CONSTANT) - return gfc_get_parentheses (gfc_copy_expr (mask->value.logical - ? tsource : fsource)); + { + result = gfc_copy_expr (mask->value.logical ? tsource : fsource); + /* Parenthesis is needed to get lower bounds of 1. */ + result = gfc_get_parentheses (result); + gfc_simplify_expr (result, 1); + return result; + } if (!mask->rank || !is_constant_array_expr (mask) || !is_constant_array_expr (tsource) || !is_constant_array_expr (fsource)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 62766c21556..8bb7e7af3de 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-13 Steven G. Kargl + + PR fortran/91566 + * gfortran.dg/pr91566.f90: + 2019-09-13 Bernd Edlinger PR fortran/91716 diff --git a/gcc/testsuite/gfortran.dg/pr91566.f90 b/gcc/testsuite/gfortran.dg/pr91566.f90 new file mode 100644 index 00000000000..fdb35b44199 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91566.f90 @@ -0,0 +1,14 @@ +! { dg-do compile } +! Code contributed by Gerhard Steinmetz +program p + call q + call r +end program p + +subroutine q + print *, -merge([3,4], 0, [.false.,.true.]) +end + +subroutine r + print *, 2 + merge([3,4], 0, [.false.,.true.]) +end