diff options
author | Mikael Morin <mikael@gcc.gnu.org> | 2023-07-17 14:14:14 +0200 |
---|---|---|
committer | Mikael Morin <mikael@gcc.gnu.org> | 2023-07-17 14:14:14 +0200 |
commit | f60231e35d8d3f84f2ab6b3c19c254faa9519cf4 (patch) | |
tree | 2cf1b7312fe1357c04431da1a92d94dc03c9daad /gcc/fortran | |
parent | 3693adaf0809fa5c91ee5534abb9c6bc59b2406d (diff) | |
download | gcc-f60231e35d8d3f84f2ab6b3c19c254faa9519cf4.zip gcc-f60231e35d8d3f84f2ab6b3c19c254faa9519cf4.tar.gz gcc-f60231e35d8d3f84f2ab6b3c19c254faa9519cf4.tar.bz2 |
fortran: Factor scalar descriptor generation
The same scalar descriptor generation code is present twice, in the
case of derived type entities, and in the case of polymorphic
non-coarray entities. Factor it in preparation for a future third case
that will also need the same code for scalar descriptor generation.
gcc/fortran/ChangeLog:
* trans.cc (get_var_descr): Factor scalar descriptor generation.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/trans.cc | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index f8df330..75d77be 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -1146,7 +1146,6 @@ static void get_var_descr (gfc_se *se, gfc_expr *var) { gfc_se tmp_se; - symbol_attribute attr; gcc_assert (var); @@ -1161,16 +1160,7 @@ get_var_descr (gfc_se *se, gfc_expr *var) gfc_conv_expr_descriptor (&tmp_se, var); } else - { - gfc_conv_expr (&tmp_se, var); - - /* No copy back needed, hence set attr's allocatable/pointer - to zero. */ - gfc_clear_attr (&attr); - tmp_se.expr = gfc_conv_scalar_to_descriptor (&tmp_se, tmp_se.expr, - attr); - gcc_assert (tmp_se.post.head == NULL_TREE); - } + gfc_conv_expr (&tmp_se, var); } else { @@ -1190,20 +1180,25 @@ get_var_descr (gfc_se *se, gfc_expr *var) gfc_add_data_component (array_expr); gfc_conv_expr (&tmp_se, array_expr); gcc_assert (tmp_se.post.head == NULL_TREE); - - if (!gfc_is_coarray (array_expr)) - { - /* No copy back needed, hence set attr's allocatable/pointer - to zero. */ - gfc_clear_attr (&attr); - tmp_se.expr = gfc_conv_scalar_to_descriptor (&tmp_se, tmp_se.expr, - attr); - } - gcc_assert (tmp_se.post.head == NULL_TREE); } gfc_free_expr (array_expr); } + if (var->rank == 0) + { + if (var->ts.type == BT_DERIVED + || !gfc_is_coarray (var)) + { + /* No copy back needed, hence set attr's allocatable/pointer + to zero. */ + symbol_attribute attr; + gfc_clear_attr (&attr); + tmp_se.expr = gfc_conv_scalar_to_descriptor (&tmp_se, tmp_se.expr, + attr); + } + gcc_assert (tmp_se.post.head == NULL_TREE); + } + if (!POINTER_TYPE_P (TREE_TYPE (tmp_se.expr))) tmp_se.expr = gfc_build_addr_expr (NULL, tmp_se.expr); |