Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 162294)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -3249,8 +3249,10 @@
 
 	      /* Deallocate when leaving the scope. Nullifying is not
 		 needed.  */
-	      tmp = gfc_deallocate_with_status (se.expr, NULL_TREE, true,
-						NULL);
+	      tmp = NULL_TREE;
+	      if (!sym->attr.result)
+		tmp = gfc_deallocate_with_status (se.expr, NULL_TREE,
+						  true, NULL);
 
 	      gfc_add_init_cleanup (&try_block, gfc_finish_block (&init), tmp);
 	    }
