]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: implement conditional expression for fortran 2023
authorYuao Ma <c8ef@outlook.com>
Fri, 12 Sep 2025 12:28:19 +0000 (20:28 +0800)
committerc8ef <c8ef@outlook.com>
Sun, 14 Sep 2025 10:24:50 +0000 (18:24 +0800)
commitaf53cfeb8352b18cbc0684f04c5106db20142f7b
tree3de0e72cacf6f091a6a6c85f4e76ffc1c486eab6
parent21d1bb1922fa7cd98f2a27d002e48b488e772176
fortran: implement conditional expression for fortran 2023

This patch adds support for conditional expressions in Fortran 2023 for a
limited set of types (logical, numerical), and also includes limited support
for conditional arguments without `.nil.` support.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_expr): Add support for EXPR_CONDITIONAL.
* expr.cc (gfc_get_conditional_expr): Add cond-expr constructor.
(gfc_copy_expr, free_expr0, gfc_is_constant_expr,
simplify_conditional, gfc_simplify_expr, gfc_check_init_expr,
check_restricted, gfc_traverse_expr): Add support for EXPR_CONDITIONAL.
* frontend-passes.cc (gfc_expr_walker): Ditto.
* gfortran.h (enum expr_t): Add EXPR_CONDITIONAL.
(gfc_get_operator_expr): Format fix.
(gfc_get_conditional_expr): New decl.
* matchexp.cc
(match_conditional, match_primary): Parsing for EXPR_CONDITIONAL.
* module.cc (mio_expr): Add support for EXPR_CONDITIONAL.
* resolve.cc (resolve_conditional, gfc_resolve_expr): Ditto.
* trans-array.cc (gfc_walk_conditional_expr, gfc_walk_subexpr): Ditto.
* trans-expr.cc
(gfc_conv_conditional_expr): Codegen for EXPR_CONDITIONAL.
(gfc_apply_interface_mapping_to_expr, gfc_conv_expr,
gfc_conv_expr_reference): Add support for EXPR_CONDITIONAL.

gcc/testsuite/ChangeLog:

* gfortran.dg/conditional_1.f90: New test.
* gfortran.dg/conditional_2.f90: New test.
* gfortran.dg/conditional_3.f90: New test.
* gfortran.dg/conditional_4.f90: New test.
* gfortran.dg/conditional_5.f90: New test.
* gfortran.dg/conditional_6.f90: New test.
* gfortran.dg/conditional_7.f90: New test.
* gfortran.dg/conditional_8.f90: New test.
* gfortran.dg/conditional_9.f90: New test.
18 files changed:
gcc/fortran/dump-parse-tree.cc
gcc/fortran/expr.cc
gcc/fortran/frontend-passes.cc
gcc/fortran/gfortran.h
gcc/fortran/matchexp.cc
gcc/fortran/module.cc
gcc/fortran/resolve.cc
gcc/fortran/trans-array.cc
gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/conditional_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_4.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_5.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_6.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_7.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_8.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/conditional_9.f90 [new file with mode: 0644]