re PR fortran/71544 (gfortran compiler optimization bug when dealing with c-style...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 9 Mar 2019 19:21:24 +0000 (19:21 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 9 Mar 2019 19:21:24 +0000 (19:21 +0000)
2019-03-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/71544
* trans-types.c (gfc_typenode_for_spec) Set ts->is_c_interop of
C_PTR and C_FUNPTR.
(create_fn_spec): Mark argument as escaping if ts->is_c_interop is set.

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

PR fortran/71544
* gfortran.dg/c_ptr_tests_19.f90: New test.

From-SVN: r269532

gcc/fortran/ChangeLog
gcc/fortran/trans-types.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90 [new file with mode: 0644]

index 40b3a3247f846caafbc2c5ee102cf17978412d14..785c7313eda3cb3f08e52b0493ff46bf0f227ba0 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/71544
+       * trans-types.c (gfc_typenode_for_spec) Set ts->is_c_interop of
+       C_PTR and C_FUNPTR.
+       (create_fn_spec): Mark argument as escaping if ts->is_c_interop is set.
+
 2019-03-09  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/84504
index 58102bafed895ace49d729bb487901c39bc03626..9ae516bb666417cab0a2c4537d679955c37e82ab 100644 (file)
@@ -1176,7 +1176,8 @@ gfc_typenode_for_spec (gfc_typespec * spec, int codim)
         {
           spec->type = BT_INTEGER;
           spec->kind = gfc_index_integer_kind;
-          spec->f90_type = BT_VOID;
+         spec->f90_type = BT_VOID;
+         spec->is_c_interop = 1;  /* Mark as escaping later.  */
         }
       break;
     case BT_VOID:
@@ -2957,7 +2958,8 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
                    || f->sym->ts.u.derived->attr.pointer_comp))
            || (f->sym->ts.type == BT_CLASS
                && (CLASS_DATA (f->sym)->ts.u.derived->attr.proc_pointer_comp
-                   || CLASS_DATA (f->sym)->ts.u.derived->attr.pointer_comp)))
+                   || CLASS_DATA (f->sym)->ts.u.derived->attr.pointer_comp))
+           || (f->sym->ts.type == BT_INTEGER && f->sym->ts.is_c_interop))
          spec[spec_len++] = '.';
        else if (f->sym->attr.intent == INTENT_IN)
          spec[spec_len++] = 'r';
index 9b8655aceea80b21ee49730c589f9c95aa4774c2..b1714e4410959b349aaea94ea36be85811fe5611 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/71544
+       * gfortran.dg/c_ptr_tests_19.f90: New test.
+
 2019-03-09  John David Anglin  <dave.anglin@bell.net>
 
        * gnat.dg/debug11.adb: Skip on 32-bit hppa*-*-hpux*.
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90 b/gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90
new file mode 100644 (file)
index 0000000..2cb0b18
--- /dev/null
@@ -0,0 +1,36 @@
+! { dg-do run }
+
+! PR 71544 - this failed with some optimization options due to a
+! pointer not being marked as escaping.
+
+module store_cptr
+    use, intrinsic :: iso_c_binding
+    implicit none
+    public
+    type(c_ptr), save :: cptr
+end module store_cptr
+
+subroutine init()
+    use, intrinsic :: iso_c_binding
+    implicit none
+    integer(c_int), pointer :: a
+    allocate(a)
+    call save_cptr(c_loc(a))
+    a = 100
+end subroutine init
+
+subroutine save_cptr(cptr_in)
+    use store_cptr
+    implicit none
+    type(c_ptr), intent(in) :: cptr_in
+    cptr = cptr_in
+end subroutine save_cptr
+
+program init_fails
+    use store_cptr
+    implicit none
+    integer(c_int), pointer :: val
+    call init()
+    call c_f_pointer(cptr,val)
+    if (val /= 100) stop 1
+end program init_fails