From: Thomas Koenig Date: Sat, 2 Feb 2019 16:57:39 +0000 (+0000) Subject: re PR fortran/57048 (Handling of C_PTR and C_FUNPTR leads to reject valid) X-Git-Tag: releases/gcc-7.5.0~620 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a89ffe70888d896a6ecea12b83e89de96f4fd50;p=thirdparty%2Fgcc.git re PR fortran/57048 (Handling of C_PTR and C_FUNPTR leads to reject valid) 2019-02-02 Thomas Koenig 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 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 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b012295a1be3..62adf03bbd76 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2019-02-02 Thomas Koenig + + 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 Backport from trunk diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 5b7c56dc14c8..5625a2e6ab62 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7c0e3c0d0c43..3195c9c06797 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-02-02 Thomas Koenig + + 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 * gfortran.dg/pr68318_1.f90: Fix a dg directive. @@ -7,7 +14,7 @@ Backport from mainline 2019-01-20 Kewen Lin - * 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 index 000000000000..541f07659604 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/c_funptr_1.f90 @@ -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 index 000000000000..6db515bdf16e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/c_funptr_1_mod.f90 @@ -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