https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117303

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #6 from anlauf at gcc dot gnu.org ---
(In reply to Kirill Chilikin from comment #4)
> $ gfortran -o test2 test2.f90 -fdump-tree-gimple
> $ cat test2.f90.007t.gimple
> ... For the first call
>       {
>         static void (*<T6af>) (integer(kind=4) & restrict) C.4740 = s1;
>         set_funptr (&C.4740);
>       }
> ... For the second call
>           {
>             _3 = funloc (s1);
>             D.4741 = _3; 
>             set_funptr (&D.4741);
>           }

Thanks for this observation!

I tried to find out where the static temporary is generated for the first
call and played with the following (otherwise untested) workaround:

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index eb050506a34..b8d6bfa2771 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -10723,7 +10762,10 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr)
   gfc_conv_expr (se, expr);

   /* Create a temporary var to hold the value.  */
-  if (TREE_CONSTANT (se->expr))
+  if (TREE_CONSTANT (se->expr)
+      && !(expr->expr_type == EXPR_FUNCTION
+          && expr->value.function.isym
+          && expr->value.function.isym->id == GFC_ISYM_C_FUNLOC))
     {
       tree tmp = se->expr;
       STRIP_TYPE_NOPS (tmp);

I don't think that this hack is correct.  But what I do not understand is
why gfc_conv_expr thinks the function is tree_constant.

Reply via email to