public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix comparison of array types
@ 2024-03-20 15:45 Hannes Domani
  0 siblings, 0 replies; only message in thread
From: Hannes Domani @ 2024-03-20 15:45 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=105470cd79f6d8c62b9156ce45e992895b01b13b

commit 105470cd79f6d8c62b9156ce45e992895b01b13b
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Mon Dec 25 19:05:55 2023 +0100

    Fix comparison of array types
    
    Currently it's not possible to call functions if an argument is a
    pointer to an array:
    ```
    (gdb) l f
    1       int f (int (*x)[2])
    2       {
    3         return x[0][1];
    4       }
    5
    6       int main()
    7       {
    8         int a[2][2] = {{0, 1}, {2, 3}};
    9         return f (a);
    10      }
    (gdb) p f(a)
    Cannot resolve function f to any overloaded instance
    ```
    
    This happens because types_equal doesn't handle array types, so the
    function is never even considered as a possibility.
    
    With array type handling added, by comparing element types and array
    bounds, the same works:
    ```
    (gdb) p f(a)
    $1 = 1
    ```
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15398
    Co-Authored-By: Keith Seitz <keiths@redhat.com>
    Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/gdbtypes.c                    | 13 +++++++++++++
 gdb/testsuite/gdb.cp/converts.exp |  1 +
 2 files changed, 14 insertions(+)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 599a696839e..960a7f49e45 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4207,6 +4207,19 @@ types_equal (struct type *a, struct type *b)
       return true;
     }
 
+  /* Two array types are the same if they have the same element types
+     and array bounds.  */
+  if (a->code () == TYPE_CODE_ARRAY)
+    {
+      if (!types_equal (a->target_type (), b->target_type ()))
+	return false;
+
+      if (*a->bounds () != *b->bounds ())
+	return false;
+
+      return true;
+    }
+
   return false;
 }
 \f
diff --git a/gdb/testsuite/gdb.cp/converts.exp b/gdb/testsuite/gdb.cp/converts.exp
index bf608bdcccd..6ea21fec563 100644
--- a/gdb/testsuite/gdb.cp/converts.exp
+++ b/gdb/testsuite/gdb.cp/converts.exp
@@ -48,6 +48,7 @@ gdb_test "p foo1_8 (bp)" "Using non-standard.*" "pointer to long int"
 gdb_test "p foo1_5 (b)" "= 15"             "pointer pointer to void pointer"
 gdb_test "p foo2_1 (b)" "= 21"             "pointer pointer to pointer pointer"
 gdb_test "p foo2_2 (b)" "Cannot resolve.*" "pointer pointer to array of arrays"
+gdb_test "p foo2_2 (ba)" "= 22"            "array of arrays to array of arrays"
 gdb_test "p foo2_3 (b)" "= 23"             "pointer pointer to array of pointers"
 gdb_test "p foo2_4 (b)" "Cannot resolve.*" "pointer pointer to array of wrong pointers"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-20 15:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 15:45 [binutils-gdb] Fix comparison of array types Hannes Domani

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