public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "abensonca at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/94446] Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
Date: Mon, 29 Mar 2021 22:01:53 +0000	[thread overview]
Message-ID: <bug-94446-4-zTqhukjYQv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94446-4@http.gcc.gnu.org/bugzilla/>

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.

  parent reply	other threads:[~2021-03-29 22:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-01 16:05 [Bug fortran/94446] New: " abensonca at gcc dot gnu.org
2021-02-14 18:27 ` [Bug fortran/94446] " dominiq at lps dot ens.fr
2021-03-29 22:01 ` abensonca at gmail dot com [this message]
2021-04-09 22:14 ` burnus at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94446-4-zTqhukjYQv@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).