re PR fortran/49232 (Pointer assignment of stride to CONTIGUOUS pointer not diagnosed...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 7 Oct 2017 11:48:28 +0000 (11:48 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 7 Oct 2017 11:48:28 +0000 (11:48 +0000)
2017-10-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/49232
* expr.c (gfc_check_pointer_assign): Error
for non-contiguous rhs.

2017-10-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/49232
* gfortran.dg/contiguous_4.f90: New test.

From-SVN: r253509

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

index 8d3e35f0e7d5785563b9cf311c878b98436654da..67a5b02e43b268997f02d4915513b38c0497f5b6 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-07  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/49232
+       * expr.c (gfc_check_pointer_assign): Error
+       for non-contiguous rhs.
+
 2017-10-07  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        * gfortran.h (async_io_dt): Add external reference.
index bfbb19ee577fab64ef433983a0f2510c3adcaba6..bc05db2fbaeade43402c27d79ecebbc78301858e 100644 (file)
@@ -3851,6 +3851,14 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue)
          }
     }
 
+  /* Error for assignments of contiguous pointers to targets which is not
+     contiguous.  Be lenient in the definition of what counts as
+     congiguous.  */
+
+  if (lhs_attr.contiguous && !gfc_is_simply_contiguous (rvalue, false, true))
+    gfc_error ("Assignment to contiguous pointer from non-contiguous "
+              "target at %L", &rvalue->where);
+
   /* Warn if it is the LHS pointer may lives longer than the RHS target.  */
   if (warn_target_lifetime
       && rvalue->expr_type == EXPR_VARIABLE
index e48f743168c36dae8686fdeb3bdeb5cd25e1d97f..319518c6e8a0b073f13cb71335f58ea5f7f14882 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-07  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/49232
+       * gfortran.dg/contiguous_4.f90: New test.
+
 2017-10-06  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/66690
diff --git a/gcc/testsuite/gfortran.dg/contiguous_4.f90 b/gcc/testsuite/gfortran.dg/contiguous_4.f90
new file mode 100644 (file)
index 0000000..b05dcfb
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+program cont_01_neg
+  implicit none
+  real, pointer, contiguous :: r(:)
+  real, pointer, contiguous :: r2(:,:)
+  real, target :: x(45)
+  real, target :: x2(5,9)
+  integer :: i
+  integer :: n=1
+
+  x = (/ (real(i),i=1,45) /)
+  x2 = reshape(x,shape(x2))
+  r => x(::3)   ! { dg-error "Assignment to contiguous pointer" }
+  r2 => x2(2:,:) ! { dg-error "Assignment to contiguous pointer" }
+  r2 => x2(:,2:3)
+  r => x2(2:3,1)
+  r => x(::1)
+  r => x(::n) ! { dg-error "Assignment to contiguous pointer" }
+end program