https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70937

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
So it looks like we gimplify type sizes multiple times (in what order?!) and
from

  ..__result = MAX_EXPR <*n, 0>;
    typedef character(kind=1) struct
character(kind=1)[1:2][1:..__result][1:2][1:..__result];
  {
    integer(kind=8) D.3659;

    ..__result = MAX_EXPR <*n, 0>;
    D.3659 = __result->dim[0].stride;
    stride.24 = D.3659 != 0 ? D.3659 : 1;
    __result.0 = (character(kind=1)[0:D.3662][1:..__result] * restrict)
__result->data;
    size.26 = stride.24 * 2;
    offset.25 = -stride.24;
    D.3660 = (bitsizetype) (sizetype) ..__result * 8;
    D.3661 = (sizetype) ..__result;
    D.3662 = size.26 + -1;
    D.3663 = SAVE_EXPR <D.3660> * (bitsizetype) (sizetype) size.26;
    D.3664 = SAVE_EXPR <D.3661> * (sizetype) size.26;
        typedef character(kind=1) struct
character(kind=1)[1:2][1:..__result][1:2][1:..__result];

produce

  _1 = *n;
  ..__result = MAX_EXPR <_1, 0>;
  D.4154 = D.3660;
  D.4155 = D.4154 * 2;
  D.4156 = D.3661;
  D.4157 = D.4156 * 2;
  {
    integer(kind=8) D.3659;

    _4 = *n;
    ..__result = MAX_EXPR <_4, 0>;
    D.3659 = __result->dim[0].stride;
    if (D.3659 != 0) goto <D.4159>; else goto <D.4160>;
    <D.4159>:
    iftmp.68 = D.3659;
    goto <D.4161>;
    <D.4160>:
    iftmp.68 = 1;
    <D.4161>:
    stride.24 = iftmp.68;
    __result.0 = __result->data;
    size.26 = stride.24 * 2;
    offset.25 = -stride.24;
    _5 = (sizetype) ..__result;
    _6 = (bitsizetype) _5;
    D.3660 = _6 * 8;
    D.3661 = (sizetype) ..__result;
...

note how the first DECL_EXPR gets gimplifier handling (not strictly needed,
only needed for unsharing) while the second "array" was
gfc_trans_vla_type_sizes'ized.

Note the respective array types are the multi-dimensional ones and are created
for debug info only.

Another "fix" is to avoid the sharing issue between IL and save-expr contents
by simply making sure the IL we emit has no sharing issues.  So the following
also avoids the ICE on the original testcase and should be moderately
light-weight (eventually the gimplifier unshares these anyway).

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 235945)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.
 /* Only for gfc_trans_code.  Shouldn't need to include this.  */
 #include "trans-stmt.h"
 #include "gomp-constants.h"
+#include "gimplify.h"

 #define MAX_LABEL_VALUE 99999

@@ -3738,7 +3739,7 @@ gfc_trans_vla_one_sizepos (tree *tp, stm

   var = gfc_create_var_np (TREE_TYPE (t), NULL);
   gfc_add_decl_to_function (var);
-  gfc_add_modify (body, var, val);
+  gfc_add_modify (body, var, unshare_expr (val));
   if (TREE_CODE (t) == SAVE_EXPR)
     TREE_OPERAND (t, 0) = var;
   *tp = var;

testing this variant as well now.  No results before monday.

Reply via email to