diff mbox

[Fortran,OOP] PR 50225: The allocation status for polymorphic allocatable function results is not set properly

Message ID CAKwh3qhv9kteQ9o7E9_QpWNCApsaqjYgPUvPo4AbrNDKX54w6A@mail.gmail.com
State New
Headers show

Commit Message

Janus Weil Aug. 29, 2011, 8:28 p.m. UTC
Hi all,

here is a relatively simple patch which fixes the PR in the subject
line. The problem was: For functions with polymorphic allocatable
result, the result variable was not nullified at the start.

The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2011-08-29  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50225
	* trans-decl.c (gfc_generate_function_code): Nullify polymorphic
	allocatable function results.

2011-08-29  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50225
	* gfortran.dg/class_result_1.f03: New.

Comments

Tobias Burnus Aug. 29, 2011, 9:29 p.m. UTC | #1
Am 29.08.2011 22:28, schrieb Janus Weil:
> Hi all,
>
> here is a relatively simple patch which fixes the PR in the subject
> line. The problem was: For functions with polymorphic allocatable
> result, the result variable was not nullified at the start.
>
> The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

OK. Looks rather obvious.


Tobias

> 2011-08-29  Janus Weil<janus@gcc.gnu.org>
>
> 	PR fortran/50225
> 	* trans-decl.c (gfc_generate_function_code): Nullify polymorphic
> 	allocatable function results.
>
> 2011-08-29  Janus Weil<janus@gcc.gnu.org>
>
> 	PR fortran/50225
> 	* gfortran.dg/class_result_1.f03: New.
Janus Weil Aug. 29, 2011, 9:56 p.m. UTC | #2
>> The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?
>
> OK. Looks rather obvious.

Thanks. Committed as r178262.

Cheers,
Janus



>> 2011-08-29  Janus Weil<janus@gcc.gnu.org>
>>
>>        PR fortran/50225
>>        * trans-decl.c (gfc_generate_function_code): Nullify polymorphic
>>        allocatable function results.
>>
>> 2011-08-29  Janus Weil<janus@gcc.gnu.org>
>>
>>        PR fortran/50225
>>        * gfortran.dg/class_result_1.f03: New.
>
>
diff mbox

Patch

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 178253)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -5215,17 +5215,25 @@  gfc_generate_function_code (gfc_namespace * ns)
     {
       tree result = get_proc_result (sym);
 
-      if (result != NULL_TREE
-	    && sym->attr.function
-	    && !sym->attr.pointer)
+      if (result != NULL_TREE && sym->attr.function && !sym->attr.pointer)
 	{
 	  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_CLASS
+		   && CLASS_DATA (sym)->attr.allocatable
+		   && sym->attr.dimension == 0 && sym->result == sym)
+	    {
+	      tmp = CLASS_DATA (sym)->backend_decl;
+	      tmp = fold_build3_loc (input_location, COMPONENT_REF,
+				     TREE_TYPE (tmp), result, tmp, NULL_TREE);
+	      gfc_add_modify (&init, tmp, fold_convert (TREE_TYPE (tmp),
+							null_pointer_node));
+	    }
 	  else if (sym->ts.type == BT_DERIVED
-	      && sym->ts.u.derived->attr.alloc_comp
-	      && !sym->attr.allocatable)
+		   && 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);