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



--- Comment #18 from janus at gcc dot gnu.org 2013-02-06 11:44:46 UTC ---

Here is an updated patch, which works for pointers and pointer components, uses

GFC_STD_F2008 and does some minor refactoring:



Index: gcc/fortran/trans-array.c

===================================================================

--- gcc/fortran/trans-array.c    (revision 195800)

+++ gcc/fortran/trans-array.c    (working copy)

@@ -7156,12 +7156,26 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr *

       ptr = build_call_expr_loc (input_location,

                  gfor_fndecl_in_pack, 1, desc);



-      if (fsym && fsym->attr.optional && sym && sym->attr.optional)

+      if (fsym && fsym->attr.optional)

     {

-      tmp = gfc_conv_expr_present (sym);

-      ptr = build3_loc (input_location, COND_EXPR, TREE_TYPE (se->expr),

+      if (sym && sym->attr.optional)

+        {

+          tmp = gfc_conv_expr_present (sym);

+          ptr = build3_loc (input_location, COND_EXPR, TREE_TYPE (se->expr),

             tmp, fold_convert (TREE_TYPE (se->expr), ptr),

             fold_convert (TREE_TYPE (se->expr), null_pointer_node));

+        }

+      else if ((gfc_option.allow_std & GFC_STD_F2008)

+           && gfc_expr_attr (expr).pointer)

+        {

+          tmp = build_fold_indirect_ref_loc (input_location, desc);

+          tmp = gfc_conv_array_data (tmp);

+          tmp = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,

+            tmp, fold_convert (TREE_TYPE (tmp), null_pointer_node));

+          ptr = build3_loc (input_location, COND_EXPR, TREE_TYPE (se->expr),

+            tmp, fold_convert (TREE_TYPE (se->expr), ptr),

+            fold_convert (TREE_TYPE (se->expr), null_pointer_node));

+        }

     }



       ptr = gfc_evaluate_now (ptr, &se->pre);





I think this should be sufficient to fix the regression in

class_optional_2.f90. I suggest everything else should wait for 4.9. (At this

point, producing a stable release should have priority over fixing more

non-regression bugs.)



Btw, as an alternative: Wouldn't it be more reasonable to move the above check

into _gfortran_internal_pack?

Reply via email to