https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66927
--- Comment #6 from vehre at gcc dot gnu.org ---
This fixes the issue:
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 6409f7f..181cbce 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5189,7 +5189,9 @@ gfc_trans_allocate (gfc_code * code)
/* Get the descriptor for all arrays, that are not allocatable or
pointer, because the latter are descriptors already. */
attr = gfc_expr_attr (code->expr3);
- if (code->expr3->rank != 0 && !attr.allocatable && !attr.pointer)
+ if (code->expr3->rank != 0 && ((!attr.allocatable && !attr.pointer)
+ || (code->expr3->expr_type == EXPR_FUNCTION
+ && code->expr3->ts.type != BT_CLASS)))
gfc_conv_expr_descriptor (&se, code->expr3);
else
gfc_conv_expr_reference (&se, code->expr3);