diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-11-28 20:43:02 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-11-29 19:11:10 +0100 |
commit | 3832c6f7e672e76bba74a508bf3a49740ea38046 (patch) | |
tree | d8f0e191348ffeb1dacfebf2a7a1034f8149ad5e /gcc/fortran/simplify.cc | |
parent | cca06f0d6d76b08ed4ddb7667eda93e2e9f2589e (diff) | |
download | gcc-3832c6f7e672e76bba74a508bf3a49740ea38046.zip gcc-3832c6f7e672e76bba74a508bf3a49740ea38046.tar.gz gcc-3832c6f7e672e76bba74a508bf3a49740ea38046.tar.bz2 |
Fortran: intrinsic MERGE shall use all its arguments [PR107874]
gcc/fortran/ChangeLog:
PR fortran/107874
* simplify.cc (gfc_simplify_merge): When simplifying MERGE with a
constant scalar MASK, ensure that arguments TSOURCE and FSOURCE are
either constant or will be evaluated.
* trans-intrinsic.cc (gfc_conv_intrinsic_merge): Evaluate arguments
before generating conditional expression.
gcc/testsuite/ChangeLog:
PR fortran/107874
* gfortran.dg/merge_init_expr_2.f90: Adjust code to the corrected
simplification.
* gfortran.dg/merge_1.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
Diffstat (limited to 'gcc/fortran/simplify.cc')
-rw-r--r-- | gcc/fortran/simplify.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index 9c2fea8..b618418 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -4913,7 +4913,22 @@ gfc_simplify_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask) if (mask->expr_type == EXPR_CONSTANT) { - result = gfc_copy_expr (mask->value.logical ? tsource : fsource); + /* The standard requires evaluation of all function arguments. + Simplify only when the other dropped argument (FSOURCE or TSOURCE) + is a constant expression. */ + if (mask->value.logical) + { + if (!gfc_is_constant_expr (fsource)) + return NULL; + result = gfc_copy_expr (tsource); + } + else + { + if (!gfc_is_constant_expr (tsource)) + return NULL; + result = gfc_copy_expr (fsource); + } + /* Parenthesis is needed to get lower bounds of 1. */ result = gfc_get_parentheses (result); gfc_simplify_expr (result, 1); |