]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/57048 (Handling of C_PTR and C_FUNPTR leads to reject valid)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 2 Feb 2019 16:57:39 +0000 (16:57 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 2 Feb 2019 16:57:39 +0000 (16:57 +0000)
2019-02-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/57048
Backport from trunk
* interface.c (gfc_compare_types): If a derived type and an
integer both have a derived type, and they are identical,
this is a C binding type and compares equal.

2019-02-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/57048
Backport from trunk
* gfortran.dg/c_funptr_1.f90: New file.
* gfortran.dg/c_funptr_1_mod.f90: New file.

From-SVN: r268478

gcc/fortran/ChangeLog
gcc/fortran/interface.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/c_funptr_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 [new file with mode: 0644]

index b012295a1be363bde4f3aeedac34644e01fa1b8d..62adf03bbd76ac9147a43c2f7909baee85979543 100644 (file)
@@ -1,3 +1,11 @@
+2019-02-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/57048
+       Backport from trunk
+       * interface.c (gfc_compare_types): If a derived type and an
+       integer both have a derived type, and they are identical,
+       this is a C binding type and compares equal.
+
 2019-01-27  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
index 5b7c56dc14c88e8220cedc6bdc9078ab58f2af82..5625a2e6ab625d7403bacbebb04108befec59152 100644 (file)
@@ -691,6 +691,15 @@ gfc_compare_types (gfc_typespec *ts1, gfc_typespec *ts2)
   if (ts1->type == BT_VOID || ts2->type == BT_VOID)
     return true;
 
+  /* Special case for our C interop types.  There should be a better
+     way of doing this...  */
+
+  if (((ts1->type == BT_INTEGER && ts2->type == BT_DERIVED)
+       || (ts1->type == BT_DERIVED && ts2->type == BT_INTEGER))
+      && ts1->u.derived && ts2->u.derived
+      && ts1->u.derived == ts2->u.derived)
+    return true;
+
   /* The _data component is not always present, therefore check for its
      presence before assuming, that its derived->attr is available.
      When the _data component is not present, then nevertheless the
index 7c0e3c0d0c434df6ed33e6cea4537363c2b052e2..3195c9c067977985af77af5d712ed518f9002814 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/57048
+       Backport from trunk
+       * gfortran.dg/c_funptr_1.f90: New file.
+       * gfortran.dg/c_funptr_1_mod.f90: New file.
+
 2019-01-30  Manfred Schwarb  <manfred99@gmx.ch>
 
        * gfortran.dg/pr68318_1.f90: Fix a dg directive.
@@ -7,7 +14,7 @@
        Backport from mainline
        2019-01-20  Kewen Lin  <linkw@gcc.gnu.org>
 
-       * gcc.target/powerpc/altivec_vld_vst_addr.c: Remove, split into 
+       * gcc.target/powerpc/altivec_vld_vst_addr.c: Remove, split into
        altivec_vld_vst_addr-1.c and altivec_vld_vst_addr-2.c.
        * gcc.target/powerpc/altivec_vld_vst_addr-1.c: New test.
        * gcc.target/powerpc/altivec_vld_vst_addr-2.c: Ditto.
diff --git a/gcc/testsuite/gfortran.dg/c_funptr_1.f90 b/gcc/testsuite/gfortran.dg/c_funptr_1.f90
new file mode 100644 (file)
index 0000000..541f076
--- /dev/null
@@ -0,0 +1,38 @@
+! { dg-do preprocess }
+! { dg-additional-options "-cpp" }
+! PR 57048 - this used not to compile. Original test case by Angelo
+! Graziosi.  Only works if compiled c_funptr_1_mod.f90, hence the
+! do-nothing directive above.
+module procs
+  
+  implicit none
+  private
+
+  public WndProc
+
+contains
+  function WndProc()
+    integer :: WndProc
+    
+    WndProc = 0
+  end function WndProc
+end module procs
+
+function WinMain()
+  use, intrinsic :: iso_c_binding, only: C_INT,c_sizeof,c_funloc
+  use win32_types
+  use procs
+  implicit none
+
+  integer :: WinMain
+
+  type(WNDCLASSEX_T) :: WndClass
+
+  WndClass%cbSize = int(c_sizeof(Wndclass),C_INT)
+  WndClass%lpfnWndProc = c_funloc(WndProc)
+
+  WinMain = 0
+end function WinMain
+
+program main
+end 
diff --git a/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 b/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90
new file mode 100644 (file)
index 0000000..6db515b
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg-do  run }
+! { dg-additional-sources c_funptr_1.f90 }
+! Additional module to go with c_funptr_1.f90
+module win32_types
+  use, intrinsic :: iso_c_binding, only: C_INT,C_FUNPTR
+  implicit none
+  private
+
+  public WNDCLASSEX_T
+  type, bind(C) :: WNDCLASSEX_T
+     integer(C_INT) :: cbSize
+     type(C_FUNPTR) :: lpfnWndProc
+
+  end type WNDCLASSEX_T
+
+end module win32_types