Blame SOURCES/gdb-testsuite26997-fix-array-slices-m32.patch

a8223e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
a8223e
From: Keith Seitz <keiths@redhat.com>
a8223e
Date: Thu, 10 Jun 2021 11:08:25 -0700
a8223e
Subject: gdb-testsuite26997-fix-array-slices-m32.patch
a8223e
a8223e
;; Backport "Fix gdb.fortran/array-slices.exp with -m32"
a8223e
;; (Tom de Vres)
a8223e
a8223e
   commit 10f92414d6d4a5f8eb8cbb2bf39ca86c1f9c1da5
a8223e
   Author: Tom de Vries <tdevries@suse.de>
a8223e
   Date:   Fri Jan 15 12:14:45 2021 +0100
a8223e
a8223e
    [gdb/testsuite] Fix gdb.fortran/array-slices.exp with -m32
a8223e
a8223e
    When running test-case gdb.fortran/array-slices.exp with target board
a8223e
    unix/-m32, we run into:
a8223e
    ...
a8223e
    (gdb) print /x &array4d^M
a8223e
    $69 = 0xffffb620^M
a8223e
    (gdb) print /x (&array4d) + sizeof (array4d)^M
a8223e
    $70 = 0x95c620^M
a8223e
    (gdb) FAIL: gdb.fortran/array-slices.exp: repack=on: test 9: check sizes match
a8223e
    ...
a8223e
    The expressions calculate the start and end of an array, but the calculation
a8223e
    of the end expression has an unexpected result (given that it lies before the
a8223e
    start of the array).  By printing "sizeof (array4d)" as a separate
a8223e
    expression:
a8223e
    ...
a8223e
    (gdb) print /x sizeof (array4d)
a8223e
    $1 = 0xc40
a8223e
    ...
a8223e
    it becomes clear we expected to get 0xffffb620 + 0xc40 == 0xffffc260 instead.
a8223e
a8223e
    The problem is that using the '&' returns a pointer type:
a8223e
    ...
a8223e
    (gdb) p &array4d
a8223e
    $5 = (PTR TO -> ( integer(kind=4) (-3:3,7:10,-3:3,-10:-7) )) 0xffffbe00
a8223e
    ...
a8223e
    which has the consequence that the addition is done as pointer arithmetic.
a8223e
a8223e
    Fix this by using the result of "print /x &array4d" instead of &array4d in the
a8223e
    addition.
a8223e
a8223e
    Tested on x86_64-linux.
a8223e
a8223e
    gdb/testsuite/ChangeLog:
a8223e
a8223e
    2021-01-15  Tom de Vries  <tdevries@suse.de>
a8223e
a8223e
            PR testsuite/26997
a8223e
            * gdb.fortran/array-slices.exp (run_test): Avoid pointer arithmetic
a8223e
            when adding sizeof.
a8223e
a8223e
diff --git a/gdb/testsuite/gdb.fortran/array-slices.exp b/gdb/testsuite/gdb.fortran/array-slices.exp
a8223e
--- a/gdb/testsuite/gdb.fortran/array-slices.exp
a8223e
+++ b/gdb/testsuite/gdb.fortran/array-slices.exp
a8223e
@@ -208,8 +208,9 @@ proc run_test { repack } {
a8223e
 	    set start_addr [get_hexadecimal_valueof "&${full_var_name}" \
a8223e
 				"start unknown"]
a8223e
 	    set end_addr [get_hexadecimal_valueof \
a8223e
-			      "(&${full_var_name}) + sizeof (${full_var_name})" \
a8223e
-			      "end unknown"]
a8223e
+			      "$start_addr + sizeof (${full_var_name})" \
a8223e
+			      "end unknown" \
a8223e
+			      "get end address of ${full_var_name}"]
a8223e
 
a8223e
 	    # The Fortran compiler can choose to either send a descriptor that
a8223e
 	    # describes the array slice to the subroutine, or it can repack the