public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch fortran] PR 84924 - Erroneous error in C_F_POINTER
@ 2018-03-25 11:10 Dominique d'Humières
  2018-03-25 11:20 ` Thomas König
  0 siblings, 1 reply; 3+ messages in thread
From: Dominique d'Humières @ 2018-03-25 11:10 UTC (permalink / raw)
  To: johnsonsr; +Cc: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

The attached patch allows scalar noninteroperable scalar derived type with -std=f2003 and -std=f2008.

Regstrapped on x86_64-apple-darwin17. OK for trunk?

Regards,

Dominique

2018-03-25  Seth Johnson <johnsonsr@ornl.gov>
	Dominique d'Humieres  <dominiq@gcc.gnu.org>

	PR fortran/84924
	* check.c (gfc_check_c_f_pointer): Allow scalar noninteroperable
	scalar derived type with -std=f2003 and -std=f2008.

2018-03-25  Seth Johnson <johnsonsr@ornl.gov>
	Dominique d'Humieres  <dominiq@gcc.gnu.org>

	PR fortran/84924
	* gfortran.dg/scalar_pointer_1.f90: New test.


[-- Attachment #2: patch-84924 --]
[-- Type: application/octet-stream, Size: 1597 bytes --]

--- ../_clean/gcc/fortran/check.c	2018-03-14 02:59:39.000000000 +0100
+++ gcc/fortran/check.c	2018-03-23 17:00:51.000000000 +0100
@@ -4749,7 +4749,7 @@ gfc_check_c_f_pointer (gfc_expr *cptr, g
       return false;
     }
 
-  if (!is_c_interoperable (fptr, &msg, false, true))
+  if (fptr->rank > 0 && !is_c_interoperable (fptr, &msg, false, true))
     return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR "
 			   "at %L to C_F_POINTER: %s", &fptr->where, msg);
 
--- ../_clean/gcc/testsuite/gfortran.dg/scalar_pointer_1.f90	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/scalar_pointer_1.f90	2018-03-23 21:56:23.000000000 +0100
@@ -0,0 +1,36 @@
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+! PR fortran/84924
+! Testcase contributed by Seth Johnson <johnsonsr@ornl.gov>
+!
+module ftest
+    use ISO_C_BINDING
+    implicit none
+
+    type :: Cls
+    end type
+
+    type :: ClsHandle
+        class(Cls), pointer :: ptr
+    end type
+contains
+    subroutine to_ptr(c, p)
+        use ISO_C_BINDING
+        class(Cls), intent(in), target :: c
+        type(C_PTR), intent(out) :: p
+        type(ClsHandle), pointer :: handle
+        allocate(handle)
+        handle%ptr => c
+        p = c_loc(handle)
+    end subroutine
+
+    subroutine from_ptr(p, c)
+        use ISO_C_BINDING
+        type(C_PTR), intent(in) :: p
+        class(Cls), intent(out), pointer :: c
+        type(ClsHandle), pointer :: handle
+        call c_f_pointer(cptr=p, fptr=handle)
+        c => handle%ptr
+        deallocate(handle)
+    end subroutine
+end module

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

* Re: [patch fortran] PR 84924 - Erroneous error in C_F_POINTER
  2018-03-25 11:10 [patch fortran] PR 84924 - Erroneous error in C_F_POINTER Dominique d'Humières
@ 2018-03-25 11:20 ` Thomas König
  2018-03-25 11:33   ` Dominique d'Humières
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas König @ 2018-03-25 11:20 UTC (permalink / raw)
  To: Dominique d'Humières, johnsonsr; +Cc: gfortran, gcc-patches

Hi Dominique,

> The attached patch allows scalar noninteroperable scalar derived type with -std=f2003 and -std=f2008.
> 
> Regstrapped on x86_64-apple-darwin17. OK for trunk?

OK.

Regards

	Thomas

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

* Re: [patch fortran] PR 84924 - Erroneous error in C_F_POINTER
  2018-03-25 11:20 ` Thomas König
@ 2018-03-25 11:33   ` Dominique d'Humières
  0 siblings, 0 replies; 3+ messages in thread
From: Dominique d'Humières @ 2018-03-25 11:33 UTC (permalink / raw)
  To: Thomas König; +Cc: johnsonsr, gfortran, gcc-patches

Thanks for the quick review. Committed as revision r258843.

Dominique

> Le 25 mars 2018 à 13:20, Thomas König <tk@tkoenig.net> a écrit :
> 
> Hi Dominique,
> 
>> The attached patch allows scalar noninteroperable scalar derived type with -std=f2003 and -std=f2008.
>> Regstrapped on x86_64-apple-darwin17. OK for trunk?
> 
> OK.
> 
> Regards
> 
> 	Thomas

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

end of thread, other threads:[~2018-03-25 11:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-25 11:10 [patch fortran] PR 84924 - Erroneous error in C_F_POINTER Dominique d'Humières
2018-03-25 11:20 ` Thomas König
2018-03-25 11:33   ` Dominique d'Humières

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