public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
       [not found] <bug-37829-4@http.gcc.gnu.org/bugzilla/>
@ 2011-01-13  6:40 ` jvdelisle at gcc dot gnu.org
  2011-11-09 14:02 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2011-01-13  6:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot
                   |                            |gnu.org
      Known to fail|                            |

--- Comment #16 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2011-01-13 05:46:01 UTC ---
>From c.l.f James Van Buskirk; Elusive bug PR37829

That bug bugs me so bad and it's hard to reproduce, but I found a
trigger:

C:\gfortran\clf\opengl2>type bug1.f90
module m3
   use ISO_C_BINDING
   implicit none
   private

   public kill_C_PTR
   interface
      function kill_C_PTR() bind(C)
         import
         implicit none
         type(C_PTR) kill_C_PTR
      end function kill_C_PTR
   end interface

   public kill_C_FUNPTR
   interface
      function kill_C_FUNPTR() bind(C)
         import
         implicit none
         type(C_FUNPTR) kill_C_FUNPTR
      end function kill_C_FUNPTR
   end interface
end module m3

module m1
   use m3
end module m1

program X
   use m1
   use ISO_C_BINDING
   implicit none
   type(C_PTR) cp
   type(C_FUNPTR) fp
   integer(C_INT),target :: i
   interface
      function fun() bind(C)
         use ISO_C_BINDING
         implicit none
         real(C_FLOAT) fun
      end function fun
   end interface

   cp = C_NULL_PTR
   cp = C_LOC(i)
   fp = C_NULL_FUNPTR
   fp = C_FUNLOC(fun)
end program X

function fun() bind(C)
   use ISO_C_BINDING
   implicit none
   real(C_FLOAT) fun
   fun = 1.0
end function fun

function kill_C_PTR() bind(C)
   use ISO_C_BINDING
   implicit none
   type(C_PTR) kill_C_PTR
   integer(C_INT), pointer :: p
   allocate(p)
   kill_C_PTR = C_LOC(p)
end function kill_C_PTR

function kill_C_FUNPTR() bind(C)
   use ISO_C_BINDING
   implicit none
   type(C_FUNPTR) kill_C_FUNPTR
   interface
      function fun() bind(C)
         use ISO_C_BINDING
         implicit none
         real(C_FLOAT) fun
      end function fun
   end interface
   kill_C_FUNPTR = C_FUNLOC(fun)
end function kill_C_FUNPTR

C:\gfortran\clf\opengl2>gfortran bug1.f90 -obug1
bug1.f90:44.8:

   cp = C_NULL_PTR
        1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at 
(1)
bug1.f90:45.8:

   cp = C_LOC(i)
        1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at 
(1)
bug1.f90:46.8:

   fp = C_NULL_FUNPTR
        1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to 
TYPE(c_funptr) at
 (1)
bug1.f90:47.8:

   fp = C_FUNLOC(fun)
        1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to 
TYPE(c_funptr) at
 (1)
bug1.f90:63.16:

   kill_C_PTR = C_LOC(p)
                1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_ptr) to TYPE(c_ptr) at 
(1)
bug1.f90:77.19:

   kill_C_FUNPTR = C_FUNLOC(fun)
                   1
Error: Can't convert TYPE(_gfortran_iso_c_binding_c_funptr) to 
TYPE(c_funptr) at
 (1)

It's the use of a function with result of TYPE(C_PTR) that kills
C_PTR subsequently and similarly the function with a result of
TYPE(C_FUNPTR) kills off C_FUNPTR.  Abstract interfaces do the trick
as well as interfaces to realized functions.  Note that directly
USEing module m3 in program X above isn't sufficient to trigger the
bug: m3 needs to be USEd in intermediate module m1 which then is
USEd in program X.

It's hard to set this one off, but when you do, look out!  Note that
the last two failures occur in external functions that don't even
USE module m3 or m1 directly or indirectly, yet they still fall
victim once the compiler has come off the rails.


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
       [not found] <bug-37829-4@http.gcc.gnu.org/bugzilla/>
  2011-01-13  6:40 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding jvdelisle at gcc dot gnu.org
@ 2011-11-09 14:02 ` burnus at gcc dot gnu.org
  2011-11-16 21:58 ` burnus at gcc dot gnu.org
  2011-11-16 22:21 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-09 14:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829

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

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

--- Comment #17 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-09 13:55:29 UTC ---
Patch, which also fixes this bug:
  http://gcc.gnu.org/ml/fortran/2011-11/msg00061.html


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
       [not found] <bug-37829-4@http.gcc.gnu.org/bugzilla/>
  2011-01-13  6:40 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding jvdelisle at gcc dot gnu.org
  2011-11-09 14:02 ` burnus at gcc dot gnu.org
@ 2011-11-16 21:58 ` burnus at gcc dot gnu.org
  2011-11-16 22:21 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-16 21:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829

--- Comment #18 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-16 21:37:47 UTC ---
Author: burnus
Date: Wed Nov 16 21:37:43 2011
New Revision: 181425

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181425
Log:
gcc/fortran
2011-11-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/39427
        PR fortran/37829
        * decl.c (match_data_constant, match_data_constant,
        * variable_decl,
        gfc_match_decl_type_spec, access_attr_decl,
        check_extended_derived_type, gfc_match_derived_decl,
        gfc_match_derived_decl, gfc_match_derived_decl) Modified to deal
        with DT constructors.
        * gfortran.h (gfc_find_dt_in_generic,
        gfc_convert_to_structure_constructor): New function prototypes.
        * interface.c (check_interface0, check_interface1,
        gfc_search_interface): Ignore DT constructors in generic list.
        * match.h (gfc_match_structure_constructor): Update prototype.
        * match.c (match_derived_type_spec): Ensure that one uses the DT
        not the generic function.
        * module.c (MOD_VERSION): Bump.
        (dt_lower_string, dt_upper_string): New functions.
        (find_use_name_n, find_use_operator, compare_true_names,
        find_true_name, add_true_name, fix_mio_expr, load_needed,
        read_module, write_dt_extensions, write_symbol): Changes to deal with
        different symtree vs. sym names.
        (create_derived_type): Create also generic procedure.
        * parse.c (gfc_fixup_sibling_symbols): Don't regard DT and
        * generic
        function as the same.
        * primary.c (gfc_convert_to_structure_constructor): New
        * function.
        (gfc_match_structure_constructor): Restructured; calls
        gfc_convert_to_structure_constructor.
        (build_actual_constructor, gfc_match_rvalue): Update for DT generic
        functions.
        * resolve.c (resolve_formal_arglist, resolve_structure_cons,
        is_illegal_recursion, resolve_generic_f, resolve_variable,
        resolve_fl_variable_derived, resolve_fl_derived0,
        resolve_symbol): Handle DT and DT generic constructors.
        * symbol.c (gfc_use_derived, gfc_undo_symbols,
        gen_special_c_interop_ptr, gen_cptr_param,
        generate_isocbinding_symbol, gfc_get_derived_super_type): Handle
        derived-types, which are hidden in the generic type.
        (gfc_find_dt_in_generic): New function
        * trans-array.c (gfc_conv_array_initializer): Replace
        * FL_PARAMETER
        expr by actual value.
        * trans-decl.c (gfc_get_module_backend_decl,
        * gfc_trans_use_stmts):
        Ensure that we use the DT and not the generic function.
        * trans-types.c (gfc_get_derived_type): Ensure that we use the
        * DT
        and not the generic procedure.

gcc/testsuite/
2011-11-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/39427
        PR fortran/37829
        * gfortran.dg/constructor_1.f90: New.
        * gfortran.dg/constructor_2.f90: New.
        * gfortran.dg/constructor_3.f90: New.
        * gfortran.dg/constructor_4.f90: New.
        * gfortran.dg/constructor_5.f90: New.
        * gfortran.dg/constructor_6.f90: New.
        * gfortran.dg/use_only_5.f90: New.
        * gfortran.dg/c_ptr_tests_17.f90: New.
        * gfortran.dg/c_ptr_tests_18.f90: New.
        * gfortran.dg/used_types_25.f90: New.
        * gfortran.dg/used_types_26.f90: New
        * gfortran.dg/type_decl_3.f90: New.
        * gfortran.dg/function_types_3.f90: Update dg-error.
        * gfortran.dg/result_1.f90: Ditto.
        * gfortran.dg/structure_constructor_3.f03: Ditto.
        * gfortran.dg/structure_constructor_4.f03: Ditto.

Added:
    trunk/gcc/testsuite/gfortran.dg/c_ptr_tests_17.f90
    trunk/gcc/testsuite/gfortran.dg/c_ptr_tests_18.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_1.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_2.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_3.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_4.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_5.f90
    trunk/gcc/testsuite/gfortran.dg/constructor_6.f90
    trunk/gcc/testsuite/gfortran.dg/type_decl_3.f90
    trunk/gcc/testsuite/gfortran.dg/use_only_5.f90
    trunk/gcc/testsuite/gfortran.dg/used_types_25.f90
    trunk/gcc/testsuite/gfortran.dg/used_types_26.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/function_types_3.f90
    trunk/gcc/testsuite/gfortran.dg/result_1.f90
    trunk/gcc/testsuite/gfortran.dg/structure_constructor_3.f03
    trunk/gcc/testsuite/gfortran.dg/structure_constructor_4.f03


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
       [not found] <bug-37829-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-11-16 21:58 ` burnus at gcc dot gnu.org
@ 2011-11-16 22:21 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-16 22:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-16 21:53:39 UTC ---
Should now be FIXED on the 4.7 trunk.

Thanks Jakub and Joe for the report(s).


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
  2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-08-14  9:31 ` burnus at gcc dot gnu dot org
@ 2010-08-14 16:24 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-14 16:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #15 from burnus at gcc dot gnu dot org  2010-08-14 16:24 -------
Ignore comment 14 - that's PR fortran/45211. Sorry.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
  2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-08-05 17:51 ` mikael at gcc dot gnu dot org
@ 2010-08-14  9:31 ` burnus at gcc dot gnu dot org
  2010-08-14 16:24 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-14  9:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #14 from burnus at gcc dot gnu dot org  2010-08-14 09:31 -------
Cf.
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/887251d8cd64eb02

Lightly tested patch. The ts.is_c_interop is only set when via
verify_bind_c_derived_type, which is called by resolve.c - and thus comes too
late.

I am not sure whether this now allows DT which are not BIND(C) and whether one
thus should add an !attr.resolved, but I assume that incompatibilities between
the BIND(C) attribute for the DT and the actual DT will be found at resolution
time. Thus, the patch should be fine.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (Revision 163239)
+++ gcc/fortran/decl.c  (Arbeitskopie)
@@ -991,7 +991,7 @@ verify_c_interop_param (gfc_symbol *sym)
              /* Make personalized messages to give better feedback.  */
              if (sym->ts.type == BT_DERIVED)
                gfc_error ("Type '%s' at %L is a parameter to the BIND(C) "
-                          " procedure '%s' but is not C interoperable "
+                          "procedure '%s' but is not C interoperable "
                           "because derived type '%s' is not C interoperable",
                           sym->name, &(sym->declared_at),
                           sym->ns->proc_name->name, 
@@ -3612,7 +3612,8 @@ gfc_try
 verify_c_interop (gfc_typespec *ts)
 {
   if (ts->type == BT_DERIVED && ts->u.derived != NULL)
-    return (ts->u.derived->ts.is_c_interop ? SUCCESS : FAILURE);
+    return (ts->u.derived->ts.is_c_interop || ts->u.derived->attr.is_bind_c)
+          ? SUCCESS : FAILURE;
   else if (ts->is_c_interop != 1)
     return FAILURE;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
  2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
  2010-07-09  8:39 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding burnus at gcc dot gnu dot org
  2010-07-09  8:48 ` burnus at gcc dot gnu dot org
@ 2010-08-05 17:51 ` mikael at gcc dot gnu dot org
  2010-08-14  9:31 ` burnus at gcc dot gnu dot org
  2010-08-14 16:24 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu dot org @ 2010-08-05 17:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from mikael at gcc dot gnu dot org  2010-08-05 17:51 -------
*** Bug 45190 has been marked as a duplicate of this bug. ***


-- 

mikael at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mathewc at nag dot co dot uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
  2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
  2010-07-09  8:39 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding burnus at gcc dot gnu dot org
@ 2010-07-09  8:48 ` burnus at gcc dot gnu dot org
  2010-08-05 17:51 ` mikael at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-07-09  8:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from burnus at gcc dot gnu dot org  2010-07-09 08:48 -------
For intrinsic modules, we currently have:

  use iso_c_binding, only: c_null_ptr

which use-associates a constant (PARAMETER) of the type "c_ptr" - but "c_ptr"
is not imported directly; to make the type information available, gfortran
currently imports "c_ptr" in a hidden way (_gfortran_...).

But the problem is the same for nonintrinsic modules. Thus, the question is:
How does it work there - it obviously does:

module m
  type t; end type
end module m
module m2
  use m
  ! private; public :: null
  type(t), parameter :: null = t()
end module m2
module m3
  use m
  ! private; public :: sub
contains
  subroutine sub(x); type(t) :: x; end subroutine
end module m3

use m2,  only: null
use m3, only: sub
call sub(null)
contains
  subroutine sub2();  use m; type(t) :: y;  y = null; end subroutine
end


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829


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

* [Bug fortran/37829] Incorrect name mangling with iso_c_binding
  2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
@ 2010-07-09  8:39 ` burnus at gcc dot gnu dot org
  2010-07-09  8:48 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-07-09  8:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from burnus at gcc dot gnu dot org  2010-07-09 08:38 -------
*** Bug 44814 has been marked as a duplicate of this bug. ***


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|44814                       |
              nThis|                            |
                 CC|                            |jkrahn at nc dot rr dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37829


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

end of thread, other threads:[~2011-11-16 21:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-37829-4@http.gcc.gnu.org/bugzilla/>
2011-01-13  6:40 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding jvdelisle at gcc dot gnu.org
2011-11-09 14:02 ` burnus at gcc dot gnu.org
2011-11-16 21:58 ` burnus at gcc dot gnu.org
2011-11-16 22:21 ` burnus at gcc dot gnu.org
2008-10-14 20:09 [Bug fortran/37829] New: ICE in resolve_symbol jakub at gcc dot gnu dot org
2010-07-09  8:39 ` [Bug fortran/37829] Incorrect name mangling with iso_c_binding burnus at gcc dot gnu dot org
2010-07-09  8:48 ` burnus at gcc dot gnu dot org
2010-08-05 17:51 ` mikael at gcc dot gnu dot org
2010-08-14  9:31 ` burnus at gcc dot gnu dot org
2010-08-14 16:24 ` burnus at gcc dot gnu dot 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).