From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2111) id 8DE453858D1E; Wed, 20 Mar 2024 15:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DE453858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710949537; bh=/rTq1WXh/ms0a3Ghkr/DSYh/XAg4+9FkoruT339pnhE=; h=From:To:Subject:Date:From; b=G+A6PZx8QBb44T/aFY0033vNG6cNA4/tusoBTSwPt4opnUKn4k6F6hi02UaD+PkXD pXayGCpBWGwTAzBvOKtCyOt3XBZmS0a6tV7tHdGyuNFs9SmlxMg1yLskLs080KR8IL uVSUpCEDUmWbsgxl77bQVFs/+ghCwL2mfYD1BFj8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Hannes Domani To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix comparison of array types X-Act-Checkin: binutils-gdb X-Git-Author: Hannes Domani X-Git-Refname: refs/heads/master X-Git-Oldrev: 53ff349e553fa9fc446a8711e37fd252282b088b X-Git-Newrev: 105470cd79f6d8c62b9156ce45e992895b01b13b Message-Id: <20240320154537.8DE453858D1E@sourceware.org> Date: Wed, 20 Mar 2024 15:45:37 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D105470cd79f6= d8c62b9156ce45e992895b01b13b commit 105470cd79f6d8c62b9156ce45e992895b01b13b Author: Hannes Domani Date: Mon Dec 25 19:05:55 2023 +0100 Fix comparison of array types =20 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] =3D {{0, 1}, {2, 3}}; 9 return f (a); 10 } (gdb) p f(a) Cannot resolve function f to any overloaded instance ``` =20 This happens because types_equal doesn't handle array types, so the function is never even considered as a possibility. =20 With array type handling added, by comparing element types and array bounds, the same works: ``` (gdb) p f(a) $1 =3D 1 ``` =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D15398 Co-Authored-By: Keith Seitz Reviewed-By: Guinevere Larsen Approved-By: Tom Tromey 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; } =20 + /* Two array types are the same if they have the same element types + and array bounds. */ + if (a->code () =3D=3D TYPE_CODE_ARRAY) + { + if (!types_equal (a->target_type (), b->target_type ())) + return false; + + if (*a->bounds () !=3D *b->bounds ()) + return false; + + return true; + } + return false; } =0C diff --git a/gdb/testsuite/gdb.cp/converts.exp b/gdb/testsuite/gdb.cp/conve= rts.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)" "=3D 15" "pointer pointer to void poin= ter" gdb_test "p foo2_1 (b)" "=3D 21" "pointer pointer to pointer p= ointer" gdb_test "p foo2_2 (b)" "Cannot resolve.*" "pointer pointer to array of ar= rays" +gdb_test "p foo2_2 (ba)" "=3D 22" "array of arrays to array of = arrays" gdb_test "p foo2_3 (b)" "=3D 23" "pointer pointer to array of = pointers" gdb_test "p foo2_4 (b)" "Cannot resolve.*" "pointer pointer to array of wr= ong pointers"