This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/47474] Wrong code with allocatable scalar, allocatable components as function result


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47474

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-26 15:04:53 UTC ---
Patch. The order was wrong; additionally, if there is an allocatable RESULT
variable, it seems to get zero initialized via sym->value or similarly. Thus
the sym->result == result check prevents that two "res = 0B;" lines get added.


--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -4602,16 +4716,18 @@ gfc_generate_function_code (gfc_namespace * ns)
            && sym->attr.function
            && !sym->attr.pointer)
        {
-         if (sym->ts.type == BT_DERIVED
-             && sym->ts.u.derived->attr.alloc_comp)
+         if (sym->attr.allocatable && sym->attr.dimension == 0
+             && sym->result == sym)
+           gfc_add_modify (&init, result, fold_convert (TREE_TYPE (result),
+                                                        null_pointer_node));
+         else if (sym->ts.type == BT_DERIVED
+             && sym->ts.u.derived->attr.alloc_comp
+             && !sym->attr.allocatable)
            {
              rank = sym->as ? sym->as->rank : 0;
              tmp = gfc_nullify_alloc_comp (sym->ts.u.derived, result, rank);
              gfc_add_expr_to_block (&init, tmp);
            }
-         else if (sym->attr.allocatable && sym->attr.dimension == 0)
-           gfc_add_modify (&init, result, fold_convert (TREE_TYPE (result),
-                                                        null_pointer_node));
        }

       if (result == NULL_TREE)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]