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

Andrew Benson <abensonca at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |abensonca at gmail dot com

--- Comment #2 from Andrew Benson <abensonca at gmail dot com> ---
After some more investigation this seems to be related to the following in
target-memory.c in function gfc_simplify_sizeof():

    case BT_DERIVED:
    case BT_CLASS:
    case BT_VOID:
    case BT_ASSUMED:
    case BT_PROCEDURE:
      {
        /* Determine type size without clobbering the typespec for ISO C        
           binding types.  */
        gfc_typespec ts;
        HOST_WIDE_INT size;
        ts = e->ts;
        type = gfc_typenode_for_spec (&ts);
        size = int_size_in_bytes (type);
        gcc_assert (size >= 0);
        *siz = size;
      }
      return true;


The call to gfc_typenode_for_spec() seems to cause the problem. This eventually
leads to reaching the following point:

#0  gfc_typenode_for_spec(gfc_typespec*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:1177
#1  0x0000000000962502 in gfc_sym_type(gfc_symbol*) () at
../../gcc-git/gcc/fortran/trans-types.c:2247
#2  0x0000000000960858 in gfc_get_function_type(gfc_symbol*,
gfc_actual_arglist*) () at ../../gcc-git/gcc/fortran/trans-types.c:3060
#3  0x00000000009611ed in gfc_get_ppc_type (c=<optimized out>) at
../../gcc-git/gcc/fortran/trans-types.c:2430
#4  0x0000000000961b50 in gfc_get_derived_type(gfc_symbol*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:2712
#5  0x0000000000961ae4 in gfc_get_derived_type(gfc_symbol*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:2670
#6  0x0000000000961ae4 in gfc_get_derived_type(gfc_symbol*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:2670
#7  0x0000000000961ae4 in gfc_get_derived_type(gfc_symbol*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:2670
#8  0x0000000000962115 in gfc_typenode_for_spec(gfc_typespec*, int) () at
../../gcc-git/gcc/fortran/trans-types.c:1166
#9  0x00000000008bec61 in gfc_element_size(gfc_expr*, unsigned long*) () at
../../gcc-git/gcc/fortran/target-memory.c:130
#10 0x00000000008bee33 in gfc_target_expr_size(gfc_expr*, unsigned long*) () at
../../gcc-git/gcc/fortran/target-memory.c:166
#11 0x00000000008af4f3 in gfc_simplify_sizeof (x=0x29fd3c0) at
../../gcc-git/gcc/fortran/simplify.c:7492
#12 0x0000000000829eea in do_simplify (specific=specific@entry=0x7ffff75bcc10,
e=e@entry=0x29fd5a0) at ../../gcc-git/gcc/fortran/intrinsic.c:4620
#13 0x00000000008350bc in gfc_intrinsic_func_interface(gfc_expr*, int) () at
../../gcc-git/gcc/fortran/intrinsic.c:5013
#14 0x000000000088ec57 in resolve_unknown_f (expr=0x29fd5a0) at
../../gcc-git/gcc/fortran/resolve.c:2918

which is this code:

      /* If we're dealing with either C_PTR or C_FUNPTR, we modified the        
         type and kind to fit a (void *) and the basetype returned was a        
         ptr_type_node.  We need to pass up this new information to the         
         symbol that was declared of type C_PTR or C_FUNPTR.  */
      if (spec->u.derived->ts.f90_type == BT_VOID)
        {
          spec->type = BT_INTEGER;
          spec->kind = gfc_index_integer_kind;
          spec->f90_type = BT_VOID;
          spec->is_c_interop = 1;  /* Mark as escaping later.  */
        }

My guess is that this is exactly the "clobbering" that is trying to be avoided
in gfc_simplify_sizeof(). As far as I can understand this is occurring because
the variable "gsf" in the test case is an argument to a function, so its
typespec is being retrieved and modified here.

I don't have the understanding to know how to fix this though.

The "clobbering" fix was implemented (according to git blame) in this patch:

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=48b155b991003487a50ac171ba5ca7c3409ad417

corresponding to PR50004.

Reply via email to