public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/fortran: Support negative array stride in one limited case
@ 2020-03-09  7:07 gdb-buildbot
  2020-03-09  7:07 ` Failures on Fedora-i686, branch master gdb-buildbot
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: gdb-buildbot @ 2020-03-09  7:07 UTC (permalink / raw)
  To: gdb-testers

*** TEST RESULTS FOR COMMIT 9e80cfa14ed0bdec20361ae78e74ccb937de3428 ***

commit 9e80cfa14ed0bdec20361ae78e74ccb937de3428
Author:     Andrew Burgess <andrew.burgess@embecosm.com>
AuthorDate: Sat Jan 18 22:38:29 2020 +0000
Commit:     Andrew Burgess <andrew.burgess@embecosm.com>
CommitDate: Tue Feb 25 16:03:22 2020 +0000

    gdb/fortran: Support negative array stride in one limited case
    
    This commit adds support for negative Fortran array strides in one
    limited case, that is the case of a single element array with a
    negative array stride.
    
    The changes in this commit will be required in order for more general
    negative array stride support to work correctly, however, right now
    other problems in GDB prevent negative array strides from working in
    the general case.
    
    The reason negative array strides don't currently work in the general
    case is that when dealing with such arrays, the base address for the
    objects data is actually the highest addressed element, subsequent
    elements are then accessed with a negative offset from that address,
    and GDB is not currently happy with this configuration.
    
    The changes here can be summarised as, stop treating signed values as
    unsigned, specifically, the array stride, and offsets calculated using
    the array stride.
    
    This issue was identified on the mailing list by Sergio:
    
      https://sourceware.org/ml/gdb-patches/2020-01/msg00360.html
    
    The test for this issue is a new one written by me as the copyright
    status of the original test is currently unknown.
    
    gdb/ChangeLog:
    
            * gdbtypes.c (create_array_type_with_stride): Handle negative
            array strides.
            * valarith.c (value_subscripted_rvalue): Likewise.
    
    gdb/testsuite/ChangeLog:
    
            * gdb.fortran/derived-type-striding.exp: Add a new test.
            * gdb.fortran/derived-type-striding.f90: Add pointer variable for
            new test.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 879a17a653..cb3e1854ac 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-25  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* gdbtypes.c (create_array_type_with_stride): Handle negative
+	array strides.
+	* valarith.c (value_subscripted_rvalue): Likewise.
+
 2020-02-25  Luis Machado  <luis.machado@linaro.org>
 
 	* aarch64-tdep.c (aarch64_vnv_type): Fix comment typo.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 8575893049..ef110b3044 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1223,7 +1223,7 @@ create_array_type_with_stride (struct type *result_type,
 	  && !type_not_allocated (result_type)))
     {
       LONGEST low_bound, high_bound;
-      unsigned int stride;
+      int stride;
 
       /* If the array itself doesn't provide a stride value then take
 	 whatever stride the range provides.  Don't update BIT_STRIDE as
@@ -1241,9 +1241,18 @@ create_array_type_with_stride (struct type *result_type,
 	 In such cases, the array length should be zero.  */
       if (high_bound < low_bound)
 	TYPE_LENGTH (result_type) = 0;
-      else if (stride > 0)
-	TYPE_LENGTH (result_type) =
-	  (stride * (high_bound - low_bound + 1) + 7) / 8;
+      else if (stride != 0)
+	{
+	  /* Ensure that the type length is always positive, even in the
+	     case where (for example in Fortran) we have a negative
+	     stride.  It is possible to have a single element array with a
+	     negative stride in Fortran (this doesn't mean anything
+	     special, it's still just a single element array) so do
+	     consider that case when touching this code.  */
+	  LONGEST element_count = abs (high_bound - low_bound + 1);
+	  TYPE_LENGTH (result_type)
+	    = ((abs (stride) * element_count) + 7) / 8;
+	}
       else
 	TYPE_LENGTH (result_type) =
 	  TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ccbb5be8fc..720febb65c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-25  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* gdb.fortran/derived-type-striding.exp: Add a new test.
+	* gdb.fortran/derived-type-striding.f90: Add pointer variable for
+	new test.
+
 2020-02-25  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.base/cached-source-file.exp: Avoid source file paths in test
diff --git a/gdb/testsuite/gdb.fortran/derived-type-striding.exp b/gdb/testsuite/gdb.fortran/derived-type-striding.exp
index 094843ca8b..639dc4c952 100644
--- a/gdb/testsuite/gdb.fortran/derived-type-striding.exp
+++ b/gdb/testsuite/gdb.fortran/derived-type-striding.exp
@@ -41,3 +41,5 @@ gdb_test "p point_dimension" "= \\\(2, 2, 2, 2, 2, 2, 2, 2, 2\\\)"
 # Test mixed type derived type.
 if { $gcc_with_broken_stride } { setup_kfail *-*-* gcc/92775 }
 gdb_test "p point_mixed_dimension" "= \\\(3, 3, 3, 3\\\)"
+
+gdb_test "p cloud_slice" " = \\\(\\\( x = 1, y = 2, z = 3 \\\)\\\)"
diff --git a/gdb/testsuite/gdb.fortran/derived-type-striding.f90 b/gdb/testsuite/gdb.fortran/derived-type-striding.f90
index 26829f51dc..fb537579fa 100644
--- a/gdb/testsuite/gdb.fortran/derived-type-striding.f90
+++ b/gdb/testsuite/gdb.fortran/derived-type-striding.f90
@@ -28,9 +28,11 @@ program derived_type_member_stride
     type(mixed_cartesian), dimension(10), target :: mixed_cloud
     integer(kind=8), dimension(:), pointer :: point_dimension => null()
     integer(kind=8), dimension(:), pointer :: point_mixed_dimension => null()
+    type(cartesian), dimension(:), pointer :: cloud_slice => null()
     cloud(:)%x = 1
     cloud(:)%y = 2
     cloud(:)%z = 3
+    cloud_slice => cloud(3:2:-2)
     point_dimension => cloud(1:9)%y
     mixed_cloud(:)%x = 1
     mixed_cloud(:)%y = 2
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 79b148602b..be0e0731be 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -187,7 +187,7 @@ value_subscripted_rvalue (struct value *array, LONGEST index, LONGEST lowerbound
 {
   struct type *array_type = check_typedef (value_type (array));
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
-  ULONGEST elt_size = type_length_units (elt_type);
+  LONGEST elt_size = type_length_units (elt_type);
 
   /* Fetch the bit stride and convert it to a byte stride, assuming 8 bits
      in a byte.  */
@@ -199,7 +199,7 @@ value_subscripted_rvalue (struct value *array, LONGEST index, LONGEST lowerbound
       elt_size = stride / (unit_size * 8);
     }
 
-  ULONGEST elt_offs = elt_size * (index - lowerbound);
+  LONGEST elt_offs = elt_size * (index - lowerbound);
 
   if (index < lowerbound
       || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)


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

end of thread, other threads:[~2020-03-11 20:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09  7:07 [binutils-gdb] gdb/fortran: Support negative array stride in one limited case gdb-buildbot
2020-03-09  7:07 ` Failures on Fedora-i686, branch master gdb-buildbot
2020-03-09  7:19 ` Failures on Fedora-x86_64-cc-with-index, " gdb-buildbot
2020-03-09  7:37 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2020-03-09  7:54 ` Failures on Fedora-x86_64-m64, " gdb-buildbot
2020-03-09  8:18 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot
2020-03-09  8:39 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2020-03-10  1:21 ` Failures on Ubuntu-Aarch64-m64, " gdb-buildbot
2020-03-10  1:39 ` Failures on Ubuntu-Aarch64-native-extended-gdbserver-m64, " gdb-buildbot
2020-03-10  3:27 ` Failures on Ubuntu-Aarch64-native-gdbserver-m64, " gdb-buildbot
2020-03-10 16:30 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot
2020-03-11 20:55 ` Failures on Fedora-x86_64-native-gdbserver-m32, " gdb-buildbot

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