Fix co-array allocation
authorAndrew Stubbs <ams@codesourcery.com>
Fri, 21 Sep 2018 11:25:54 +0000 (11:25 +0000)
committerAndrew Stubbs <ams@gcc.gnu.org>
Fri, 21 Sep 2018 11:25:54 +0000 (11:25 +0000)
The Fortran front-end has a bug in which it uses "int" values for "size_t"
parameters.  I don't know why this isn't problem for all 64-bit architectures,
but GCN ends up with the data in the wrong argument register and/or stack slot,
and bad things happen.

This patch corrects the issue by setting the correct type.

2018-09-21  Andrew Stubbs  <ams@codesourcery.com>
            Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/fortran/
* trans-expr.c (gfc_trans_structure_assign): Ensure that the first
argument of a call to _gfortran_caf_register is of size_type_node.
* trans-intrinsic.c (conv_intrinsic_event_query): Convert computed
index to a size_type_node type.
* trans-stmt.c (gfc_trans_event_post_wait): Likewise.

Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
From-SVN: r264468

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/fortran/trans-intrinsic.c
gcc/fortran/trans-stmt.c

index dbd05d2b23e973e3b987318829fc92d07e6db2ab..1f622495d09a666b75d1abbcc39575b45798529d 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-21  Andrew Stubbs  <ams@codesourcery.com>
+            Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * trans-expr.c (gfc_trans_structure_assign): Ensure that the first
+       argument of a call to _gfortran_caf_register is of size_type_node.
+       * trans-intrinsic.c (conv_intrinsic_event_query): Convert computed
+       index to a size_type_node type.
+       * trans-stmt.c (gfc_trans_event_post_wait): Likewise.
+
 2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
 
        * gfortranspec.c (lang_specific_driver): Handle -r like -nostdlib.
index 5a7cdb8f51972deba8579123cab2c6fdc0c51e45..1f94dcf11dd5f6f8f404cbbf872f0cf70671867d 100644 (file)
@@ -7733,7 +7733,7 @@ gfc_trans_structure_assign (tree dest, gfc_expr * expr, bool init, bool coarray)
                 suffices to recognize the data as array.  */
              if (rank < 0)
                rank = 1;
-             size = integer_zero_node;
+             size = build_zero_cst (size_type_node);
              desc = field;
              gfc_add_modify (&block, gfc_conv_descriptor_rank (desc),
                              build_int_cst (signed_char_type_node, rank));
index d068e011f25c52a6d4e05a871f8ad4e3e31fa089..11fd4b94fcc410bd3d93fe88fd29cb247dba66e5 100644 (file)
@@ -10729,7 +10729,9 @@ conv_intrinsic_event_query (gfc_code *code)
              tmp = fold_build2_loc (input_location, MULT_EXPR,
                                     integer_type_node, extent, tmp);
              index = fold_build2_loc (input_location, PLUS_EXPR,
-                                      integer_type_node, index, tmp);
+                                      gfc_array_index_type, index,
+                                      fold_convert (gfc_array_index_type,
+                                                    tmp));
              if (i < ar->dimen - 1)
                {
                  ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
@@ -10753,6 +10755,7 @@ conv_intrinsic_event_query (gfc_code *code)
          stat = gfc_create_var (integer_type_node, "stat");
        }
 
+      index = fold_convert (size_type_node, index);
       tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_event_query, 5,
                                    token, index, image_index, count
                                   ? gfc_build_addr_expr (NULL, count) : count,
index 795d3cc0a13c2033a3ca2e2a5e5eb971179d568d..92d9c3767c0aed1e2c2b706b27e1f958c08973a6 100644 (file)
@@ -1096,7 +1096,8 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op)
          tmp = fold_build2_loc (input_location, MULT_EXPR,
                                 integer_type_node, extent, tmp);
          index = fold_build2_loc (input_location, PLUS_EXPR,
-                                  integer_type_node, index, tmp);
+                                  gfc_array_index_type, index,
+                                  fold_convert (gfc_array_index_type, tmp));
          if (i < ar->dimen - 1)
            {
              ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]);
@@ -1130,6 +1131,7 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op)
       stat = gfc_create_var (integer_type_node, "stat");
     }
 
+  index = fold_convert (size_type_node, index);
   if (op == EXEC_EVENT_POST)
     tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_event_post, 6,
                               token, index, image_index,