public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Cc: Keith Seitz <keiths@redhat.com>
Subject: [PATCH] Fix comparison of array types
Date: Fri,  9 Feb 2024 20:45:45 +0100	[thread overview]
Message-ID: <20240209194545.31497-1-ssbssa@yahoo.de> (raw)
In-Reply-To: <20240209194545.31497-1-ssbssa.ref@yahoo.de>

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>
---
 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 dcd7321d979..6c0d20b2daf 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -4202,6 +4202,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"
 
-- 
2.35.1


       reply	other threads:[~2024-02-09 19:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240209194545.31497-1-ssbssa.ref@yahoo.de>
2024-02-09 19:45 ` Hannes Domani [this message]
2024-02-25 12:02   ` Hannes Domani
2024-02-29 13:26   ` Guinevere Larsen
2024-03-17 14:12     ` Hannes Domani
2024-03-18 16:26     ` Tom Tromey
2024-03-18 16:20   ` Tom Tromey
2024-03-20 15:46     ` Hannes Domani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240209194545.31497-1-ssbssa@yahoo.de \
    --to=ssbssa@yahoo.de \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).