From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B64F03858C52 for ; Thu, 29 Feb 2024 13:26:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B64F03858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B64F03858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709213177; cv=none; b=XQPtvj0ITRp7Biz9Dwbag3JnjA1ARf3jYkjekQohqQxRMeumgRrDu/1Gt5N+nIEH93qGmbMRRsJluwz7nnwXHzk0gE+XoKciKQmezHoeq+kuz4M/v/v0SAAtwA3WJk52zR9RmNQVg5DOGetwewse2Dgg+X9P1iLuVIT+MYGKO44= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709213177; c=relaxed/simple; bh=6UpJvi0GfVfBhtqAFuxMNuOP9YOZCywq1U/Sk9t9RBM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XqJOnYiR2gZp73LrxXHbBYMUPlaCJqpaN1RKympD4iZyuQrpiG+EDngzMUtdG+6CKxKgN4ldMEjMzFVfVhF0a+LBpoiQCMOP2w/EmkEDHXz3a/Qyz/7TnmH/FjIaBX5viB7kU/wCWCLjOAdhz48cFw889YdLJaz94H/ZH/PJG+w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709213175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1LGO/WSuygUGOF/0rFTZFDlRMuM2VDegVwJBvq5MO5s=; b=TZcRCK7LHT4kPYiVr4T3td8b4/XAP3resFJjGlk0O/SHMXAVevDwA7o8NqnJekwsegFziS KGh8sZjyRm/SYWwm/jPtPR5eVphmqljRvRuWBJrE/igJ0YBLzeaXEItl3Pd7TB6nIjOy8q P8UU0byu/BjkQat7d4qiiPIJSrm1nkQ= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-FRfaUfnrNcyENFfgHrS7Cg-1; Thu, 29 Feb 2024 08:26:14 -0500 X-MC-Unique: FRfaUfnrNcyENFfgHrS7Cg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a44460e6c06so29309566b.1 for ; Thu, 29 Feb 2024 05:26:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709213173; x=1709817973; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u/fgvUsE05RKehJ3DH0raGbQnL+fx4Fzk9KwqsF7SK4=; b=ev3jE7AMUEfvIfNk35J8kSfV6jenniSiq2F4u4BUGwPd8K2rnmRpKc3neZQBoxEv/J fOi3OnEXl3jJialSXFhvEbyr32qOp2a6gsyvItsoG4SqkeYgNFaQh2+BN+Edr6/juDDg T3JP3Yp9GO39as2c7nRRKdAJ/2fP6cwas4ZZWTr4CxDj0PHpJpSLSQWb8nLGAWc5FSn1 4f7V2H9PH6veLOHkqNxzy45bv9LhhwW5kxQbyJzk3yDpOGrdDREvizxe/VDqGIQOrXqi vFyLLEFLaZhMZpYcMwvPoKMCsMlDAiecoMB/gVctwBjP/tKIWC9pwq2dSgl3ijqTfuMe vIeQ== X-Forwarded-Encrypted: i=1; AJvYcCX1JGCWBxhHG0ciEgDe8Gw5Oj3jD12c/oA2zOk0TVDNNFwJVQnZ/UCiDBmvZjB22B5zncvV11gmjVS+81YdFHOrNpIJajpcTmHLGg== X-Gm-Message-State: AOJu0YyhgYxa8RlAVRVCP0sQMiEITnNSY1MRlOq0WHA84y00/lQM6K8k jiGBXDCO3FrTdSPBgIb15OAc7iuffhqfYSrs7ID0MIt63cuAcMKqRsHpmnE0eC8KPh3q5PN0Hwj /WmJDRqnrXOQrtToNyUyRqwV78i+oVvbOJ//nd88+9AlbBMYkkF4zofJRI1k= X-Received: by 2002:a17:906:b790:b0:a43:292c:2081 with SMTP id dt16-20020a170906b79000b00a43292c2081mr1309694ejb.16.1709213172911; Thu, 29 Feb 2024 05:26:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6iVF+Tnt7CRVXO+RFuA2+9npwkfddTNa/XgB7n2BAj2iR2Q/H9WOYyAreOE5iW1l51Iqu0Q== X-Received: by 2002:a17:906:b790:b0:a43:292c:2081 with SMTP id dt16-20020a170906b79000b00a43292c2081mr1309675ejb.16.1709213172455; Thu, 29 Feb 2024 05:26:12 -0800 (PST) Received: from [192.168.0.129] (ip-94-112-227-180.bb.vodafone.cz. [94.112.227.180]) by smtp.gmail.com with ESMTPSA id dr17-20020a170907721100b00a43e47c8c97sm691208ejc.173.2024.02.29.05.26.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Feb 2024 05:26:12 -0800 (PST) Message-ID: <4b9a274e-f072-4408-b797-857573a96b11@redhat.com> Date: Thu, 29 Feb 2024 14:26:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix comparison of array types To: Hannes Domani , gdb-patches@sourceware.org Cc: Keith Seitz References: <20240209194545.31497-1-ssbssa.ref@yahoo.de> <20240209194545.31497-1-ssbssa@yahoo.de> From: Guinevere Larsen In-Reply-To: <20240209194545.31497-1-ssbssa@yahoo.de> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 09/02/2024 20:45, Hannes Domani wrote: > 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 Hi! This patch fixes the problem (for both gcc and clang) and introduces no regressions. My one nitpick is that I think this code fits more naturally right after the pointer check, instead of the last check in the function, but feel free to disagree. Either way: Reviewed-By: Guinevere Larsen -- Cheers, Guinevere Larsen She/Her/Hers > --- > 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; > } > > 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" >