re PR fortran/61138 (Wrong code with pointer-bounds remapping)
authorMikael Morin <mikael@gcc.gnu.org>
Sat, 14 Mar 2015 12:23:27 +0000 (12:23 +0000)
committerMikael Morin <mikael@gcc.gnu.org>
Sat, 14 Mar 2015 12:23:27 +0000 (12:23 +0000)
PR fortran/61138
fortran/
* trans-expr.c (gfc_trans_pointer_assignment): Clear DESCRIPTOR_ONLY
field before reusing LSE.
testsuite/
gfortran.dg/pointer_remapping_9.f90: New.

From-SVN: r221436

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

index d7d854389e6883ac12d2b996d29cd4c463b2ba7d..30107c977af8580872eac1e4e4f6a33e5366a50d 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-14  Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/61138
+       * trans-expr.c (gfc_trans_pointer_assignment): Clear DESCRIPTOR_ONLY
+       field before reusing LSE.
+
 2015-03-11  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR libfortran/65200
index 353d0120d9de31688e5a37edc4a75099ef3b4466..8af8be287eec825ae50ab2e48425a0c584706d94 100644 (file)
@@ -7335,6 +7335,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2)
                                               bound, bound, 0,
                                               GFC_ARRAY_POINTER_CONT, false);
              tmp = gfc_create_var (tmp, "ptrtemp");
+             lse.descriptor_only = 0;
              lse.expr = tmp;
              lse.direct_byref = 1;
              gfc_conv_expr_descriptor (&lse, expr2);
@@ -7350,6 +7351,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2)
       else if (expr2->expr_type == EXPR_VARIABLE)
        {
          /* Assign directly to the LHS's descriptor.  */
+         lse.descriptor_only = 0;
          lse.direct_byref = 1;
          gfc_conv_expr_descriptor (&lse, expr2);
          strlen_rhs = lse.string_length;
@@ -7401,6 +7403,7 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gfc_expr * expr2)
          /* Assign to a temporary descriptor and then copy that
             temporary to the pointer.  */
          tmp = gfc_create_var (TREE_TYPE (desc), "ptrtemp");
+         lse.descriptor_only = 0;
          lse.expr = tmp;
          lse.direct_byref = 1;
          gfc_conv_expr_descriptor (&lse, expr2);
index cbd544d12b19d600f706ff4fe4a6d272c7f5b531..b4e8ac8aa895f4f91e8f54fa1eef35888e4ab4c0 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-14  Mikael Morin  <mikael@gcc.gnu.org>
+
+       PR fortran/61138
+       gfortran.dg/pointer_remapping_9.f90: New.
+
 2015-03-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/65369
diff --git a/gcc/testsuite/gfortran.dg/pointer_remapping_9.f90 b/gcc/testsuite/gfortran.dg/pointer_remapping_9.f90
new file mode 100644 (file)
index 0000000..7c1e232
--- /dev/null
@@ -0,0 +1,31 @@
+! { dg-do run }
+!
+! PR fortran/61138
+! Wrong code with pointer-bounds remapping
+!
+! Contributed by Tobias Burnus <burnus@net-b.de>
+
+implicit none
+integer, target :: tgt(10)
+integer, target, allocatable :: tgt2(:)
+integer, pointer :: ptr(:)
+
+tgt = [1,2,3,4,5,6,7,8,9,10]
+tgt2 = [1,2,3,4,5,6,7,8,9,10]
+
+
+ptr(-5:) => tgt(5:)  ! Okay
+
+if (size(ptr) /= 6 .or. lbound(ptr,1) /= -5) call abort()
+if (any (ptr /= [5,6,7,8,9,10])) call abort()
+
+
+ptr(-5:) => tgt2(5:)  ! wrongly associates the whole array
+
+print '(*(i4))', size(ptr), lbound(ptr)
+print '(*(i4))', ptr
+
+if (size(ptr) /= 6 .or. lbound(ptr,1) /= -5) call abort()
+if (any (ptr /= [5,6,7,8,9,10])) call abort()
+end
+