public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/94446] New: Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
@ 2020-04-01 16:05 abensonca at gcc dot gnu.org
  2021-02-14 18:27 ` [Bug fortran/94446] " dominiq at lps dot ens.fr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: abensonca at gcc dot gnu.org @ 2020-04-01 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94446
           Summary: Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abensonca at gcc dot gnu.org
  Target Milestone: ---

The following causes a bogus "type mismatch" error with the current trunk
(e899d4b71255b9ae096a7ecd31a61fc76f200019):

$ cat file1.F90
module nrn
  use, intrinsic :: ISO_C_Binding

  type :: rgc
     private
   contains
     procedure :: st => rgcST
  end type rgc

  type, extends(rgc) :: rgcG
     private
   contains
     procedure :: st => rgcGST
  end type rgcG

  interface
     module subroutine rgcGST(s,gsf)
       class(rgcG), intent(inout) :: s 
       type(c_ptr), intent(in   ) :: gsf
     end subroutine rgcGST
  end interface

contains

  subroutine rgcST(s,gsf)
    implicit none
    class(rgc), intent(inout) :: s
    type(c_ptr), intent(in   ) :: gsf
  end subroutine rgcST

end module nrn


$ cat file2.F90

module gn
  use :: nrn

  type, public :: mt
     class (rgc), pointer :: rgc_
  end type mt

  type, public :: tn
    type (mt), pointer :: ht
   contains
  end type tn

contains

  subroutine tnc()
    type(tn) :: a
    write (0,*) sizeof(a)
  end subroutine tnc

end module gn

module eh
  use :: gn
end module eh



$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-linux-gnu/10.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-git/configure --prefix=/home/abenson/Galacticus/Tools
--enable-languages=c,c++,fortran --disable-multilib : (reconfigured)
../gcc-git/configure --prefix=/home/abenson/Galacticus/Tools --disable-multilib
--enable-languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200401 (experimental) (GCC) 


$ gfortran -c  file1.F90 -o file1.o 

$ gfortran -c  file2.F90 -o file2.o                                             
file2.F90:24:8:

   24 |   use :: gn
      |        1
Error: Argument mismatch for the overriding procedure 'st' at (1): Type
mismatch in argument 'gsf' (TYPE(c_ptr)/INTEGER(8))


The error only occurs if the module in file1.F90 is compiled separately - if I
combine file1.F90 and file2.F90 into a single file, that single file compiles
without error.

I haven't been able to reduce the testcase further, and figuring out the cause
of the error has so far been beyond my ability. What I have found though is
that in the nrn.mod module file created by compiling file.F90 all instances of
symbol "gsf" are correctly given DERIVED type. But, in gn.mod created by
compiling file2.F90 there are two instances of symbol "gsf", the first has
DERIVED type, while the second has INTEGER type. So, it seems that the problem
occurs at (or before) the creation of the gn.mod module file.

Also, the use of the "sizeof()" intrinsic is necessary to trigger the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/94446] Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
  2020-04-01 16:05 [Bug fortran/94446] New: Bogus "type mismatch" with TYPE(c_ptr) and sizeof() abensonca at gcc dot gnu.org
@ 2021-02-14 18:27 ` dominiq at lps dot ens.fr
  2021-03-29 22:01 ` abensonca at gmail dot com
  2021-04-09 22:14 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-02-14 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-02-14

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed since at least GCC7.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/94446] Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
  2020-04-01 16:05 [Bug fortran/94446] New: Bogus "type mismatch" with TYPE(c_ptr) and sizeof() 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
  2021-04-09 22:14 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: abensonca at gmail dot com @ 2021-03-29 22:01 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/94446] Bogus "type mismatch" with TYPE(c_ptr) and sizeof()
  2020-04-01 16:05 [Bug fortran/94446] New: Bogus "type mismatch" with TYPE(c_ptr) and sizeof() 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
@ 2021-04-09 22:14 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-04-09 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 50541
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50541&action=edit
Draft patch

I wonder whether something like that would work.

The only known failure is gfortran.dg/gomp/use_device_ptr-1.f90 which fails as
instead of
  void * x;
  #pragma omp target data map(alloc:x)
the wrong
  #pragma omp target data map(alloc:*x) map(alloc:x [pointer assign, bias: 0])
is generated (ICE as sizeof 'void' does not make sense).
(Fix should be in the code block below 'case OMP_LIST_MAP:' in trans-openmp.c)

I wonder what else goes wrong with 'type(c_ptr)' and 'type(c_ptr),pointer'
besides this issue and the one 'fn spec' issue (already fixed in the attached
patch).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-09 22:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 16:05 [Bug fortran/94446] New: Bogus "type mismatch" with TYPE(c_ptr) and sizeof() 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
2021-04-09 22:14 ` burnus at gcc dot gnu.org

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).