]> gcc.gnu.org Git - gcc.git/commitdiff
re PR fortran/89384 (CONTIGUOUS dummy argument in BIND(C) interface incorrect when...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 19 Feb 2019 17:55:33 +0000 (17:55 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 19 Feb 2019 17:55:33 +0000 (17:55 +0000)
2019-02-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/89384
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): If the dummy
argument is contiguous and the actual argument may not be,
use gfc_conv_subref_array_arg.

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

PR fortran/89384
* gfortran.dg/ISO_Fortran_binding_4.f90

From-SVN: r269024

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

index 989bf9aba74c8553cb05b4a0d97dd00b76cf07c1..ae06290ca8bd50e9fe2de8a555623617045f6378 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/89384
+       * trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): If the dummy
+       argument is contiguous and the actual argument may not be,
+       use gfc_conv_subref_array_arg.
+
 2019-02-19  Chung-Lin Tang  <cltang@codesourcery.com>
 
        PR c/87924
index a75f8a7c250a19cdb1c90ccefe12cefdbeaddb92..223fd14cd7b984a05ee9bda8f6b65b90874c8991 100644 (file)
@@ -4944,7 +4944,12 @@ gfc_conv_gfc_desc_to_cfi_desc (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym)
 
   if (e->rank != 0)
     {
-      gfc_conv_expr_descriptor (parmse, e);
+      if (fsym->attr.contiguous
+         && !gfc_is_simply_contiguous (e, false, true))
+       gfc_conv_subref_array_arg (parmse, e, false, fsym->attr.intent,
+                                  fsym->attr.pointer);
+      else
+       gfc_conv_expr_descriptor (parmse, e);
 
       if (POINTER_TYPE_P (TREE_TYPE (parmse->expr)))
        parmse->expr = build_fold_indirect_ref_loc (input_location,
index 1c91cec1a815b2afbebe1927f7c94ee8f317b8da..4ea21550f0dcd2ebd17e8e7147d1be617b643bb9 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-19  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/89384
+       * gfortran.dg/ISO_Fortran_binding_4.f90
+
 2019-02-19  Thomas Schwinge  <thomas@codesourcery.com>
 
        PR c/87924
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_4.f90 b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_4.f90
new file mode 100644 (file)
index 0000000..2c6c81b
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do  run }
+! PR fortran/89384 - this used to give a wrong results
+! with contiguous.
+! Test case by Reinhold Bader.
+module mod_ctg
+  implicit none
+contains
+  subroutine ctg(x) BIND(C)
+    real, contiguous :: x(:)
+
+    if (any(abs(x - [2.,4.,6.]) > 1.e-6)) then
+       write(*,*) 'FAIL'
+    else
+       write(*,*) 'OK'
+    end if
+  end subroutine
+end module
+program p
+  use mod_ctg
+  implicit none
+  real :: x(6)
+  integer :: i
+
+  x = [ (real(i), i=1, size(x)) ]
+  call ctg(x(2::2))
+
+end program
This page took 0.082738 seconds and 5 git commands to generate.