From patchwork Tue Dec 5 15:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81432 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C458438708DC for ; Tue, 5 Dec 2023 15:37:32 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id DD0F5386D600 for ; Tue, 5 Dec 2023 15:37:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD0F5386D600 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DD0F5386D600 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701790636; cv=none; b=a8ZxD/ivAUEbhYhGhVHCruQxHfgBVk4UDw8Yj4vLz2ofJ3L+bqCbk6wOzWbmLfO2qFu8xYwF/GONZSRdf0eoMZ61RZRGUz7nf2BhmYgXsOJDAxoqQ4FPYV34Vz5brXmB0umnOMwjQS0fK76ZKZC8xSJMDXqoTfXykd7U6/F0kh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701790636; c=relaxed/simple; bh=s59VdFIb8r9c6PgMoET4uSzJNa3BLbQHsrQQtrLnky8=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=mZ9hukXTWyLTcxKHAnsqnDAbHpHhGn174uRCzgkfSqg1b7qqz/nA5dkGuHEiu+sIPW2mRMoNNnZ5X6+jq5VaiYkcR7mXOGWyl2dVv7f4ZdLqaGy0tVZZB1LcWqTnWwnMlzRqQvg5rUVMuZcsRqLHEn0RHkV6Ztlf6Injz9b8dM4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3580b94ac2eso33688105ab.0 for ; Tue, 05 Dec 2023 07:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701790634; x=1702395434; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=X9xFn3+BcTWttK5x9F9+p2mAmsT+XluzNasOP18l1Js=; b=i9tMMB5tpRrPnGnqL3qoPOIPQH3dc8d2P0mcsE6MrmxAfmzEnjJhwfX2oD+rvsQvpW 0gGv699mMti+Um4WQ/Wrgo+iOG+deHKz0a1awDjNHEmduywuaDSnxQr+ist8uQc+D4UZ rPnHaiV+WTZR4kfiu6zjIYcCDL0Au44ytPIV9vq9q01eANEei6FadIc7lhaI5kwl2bul s7BcqLQPUa04m9F/ffP2+F/qR7xYSqiitmkgAsBU7w2RAV3FsujvTvhCrRvODMHneuim YNzwZ+jBmejmL28P6rukJjrNqZNg0oyCZazRGnR7AZrDnrhS75Rg69JBwtNIWepvEjZV KuCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701790634; x=1702395434; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X9xFn3+BcTWttK5x9F9+p2mAmsT+XluzNasOP18l1Js=; b=q0r2qxhMXxkfnj+2tB0TtbAKSI1OVyKjXMvai3774t0cWErKsksjtqzi8cEZocBcFI YoijEO2f4h0GZNhHwUtmYeupELpsyNYO56T15IvPOEkEQGHQI7LTkAKeraSkf96my8yl FdfgUYUKISa4blun6iXiNk1oFnpntJSwiZ+r38lPIR4alwK82VOa6n+0VLL13OAM+qU9 R8GTtsJJ0HgUwPUEQ3LH7HCV4mzaL9F0FGlZoN7IdiafMYb60XmIwfTWcu5y7Dd6R08D hDMrl8JiLQX9jlxiOaOJq+KdPir0qWd/1KIFWizpLE/6GMAklZ1IMz3owlFsCVpM6ChQ Dndw== X-Gm-Message-State: AOJu0YxIYL2oGwZ13RfqDQrfqt71qMGbaC/5DfZFaxQ7U40ellBrVHlc b6tIBZIezYsM4oxwyzlHjHIfFlMcVJSZjAdCN9E= X-Google-Smtp-Source: AGHT+IG64z/incYSp04m83ty4GqaH0avubxUaVKcsCYeU9P4kbPbDbspupge+CYhmw+HwS6UBOixIA== X-Received: by 2002:a92:d20d:0:b0:35d:59a2:2d3 with SMTP id y13-20020a92d20d000000b0035d59a202d3mr7363400ily.115.1701790634015; Tue, 05 Dec 2023 07:37:14 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id y19-20020a02c013000000b00466a2a9e5b0sm3152510jai.32.2023.12.05.07.37.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 07:37:13 -0800 (PST) From: Tom Tromey Date: Tue, 05 Dec 2023 08:37:12 -0700 Subject: [PATCH 1/2] Boolify ada_type_match MIME-Version: 1.0 Message-Id: <20231205-ada-overload-v1-1-9d97ac80a60e@adacore.com> References: <20231205-ada-overload-v1-0-9d97ac80a60e@adacore.com> In-Reply-To: <20231205-ada-overload-v1-0-9d97ac80a60e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This changes ada_type_match to return bool. --- gdb/ada-lang.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 1a591567cda..9d5c8d5534b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3934,7 +3934,7 @@ ada_resolve_variable (struct symbol *sym, const struct block *block, /* The term "match" here is rather loose. The match is heuristic and liberal. */ -static int +static bool ada_type_match (struct type *ftype, struct type *atype) { ftype = ada_check_typedef (ftype); @@ -3951,11 +3951,11 @@ ada_type_match (struct type *ftype, struct type *atype) return ftype->code () == atype->code (); case TYPE_CODE_PTR: if (atype->code () != TYPE_CODE_PTR) - return 0; + return false; atype = atype->target_type (); /* This can only happen if the actual argument is 'null'. */ if (atype->code () == TYPE_CODE_INT && atype->length () == 0) - return 1; + return true; return ada_type_match (ftype->target_type (), atype); case TYPE_CODE_INT: case TYPE_CODE_ENUM: @@ -3965,9 +3965,9 @@ ada_type_match (struct type *ftype, struct type *atype) case TYPE_CODE_INT: case TYPE_CODE_ENUM: case TYPE_CODE_RANGE: - return 1; + return true; default: - return 0; + return false; } case TYPE_CODE_ARRAY: From patchwork Tue Dec 5 15:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81433 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F291A38708BF for ; Tue, 5 Dec 2023 15:37:32 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 7C5F4386D633 for ; Tue, 5 Dec 2023 15:37:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C5F4386D633 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7C5F4386D633 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701790637; cv=none; b=Lh8z3ktEMyRJlCJv5MT7gOug9vu6n80tc8blMe2j5VD3eRFfwmDfxRlvhEyDPpkpnrlIQ6SUGTRHnycK0YR5zI0R/VYEIYtWfZ3ptfsCvwMa7nfsJAIqRIOA8V1ZYbya1vCjt7f1xukmX5ZyX2qk0r29tVRgo30WVsdJhUqcIzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701790637; c=relaxed/simple; bh=8g2gICpxdUcaJcP07OwrhpKrWVfVbN/3DPx6c6MO1yI=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=b8RtJt5V8hATCZdLb9zgcR/lXZQU/+1ApWhZSo04VtDFbWuGMdXKPA8UxfC9u+mAvB5EQFmjE12L7Uk/vgPJNW8gdY+GmDWVbJ9P33aa6iuCObo0tVh4MdzpoataV598irl657te9cwG7czS+N5yk45E+EraCyWtU2ud1lBvF6o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3b894f5a7f3so3297325b6e.2 for ; Tue, 05 Dec 2023 07:37:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701790635; x=1702395435; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=y9gHeI2hRGQYu7gZL+6kKCo/V8MgSGdIFbVbbCQIB6M=; b=abQNAl/YnwEFfDDOXgGWWk4j0RFhZbhwI+SNinBI98/jOEHg9diFYw7RisgHL51tKc QclrfpgJNd3WQDLxm2M7cDFCaKVBa/vWE3nU3BoHynAj1kP5UqMEgegkqKl2pynAeAp4 AuaQcU3SKtWPxSuE9VSfH9wIPkLiNPHNUcMwSl9ociQmojs/zvN9rb1o8QRagRjJvm2z UveUFmbTstLeUWWGGeg09j21pgW7GfdJupOzPicae18JE7SX53/e+HlGWD58yVxI7AWB Tp/p7Btq5S/LvLpmTtJQVHjkwAT/HSzfcfmGeLu+scHJsJpW4JEKReofe+h4r+cqi0JK 2cmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701790635; x=1702395435; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y9gHeI2hRGQYu7gZL+6kKCo/V8MgSGdIFbVbbCQIB6M=; b=kJSiyFQmRHkwwKioErYtzP+L2vjh9JYu1ggYKNPFZ5yynqUZIeg0ffuXdrzpqhILWG /PWhja3gF4f2yHmC1Hc1OGooSIFzXljyGTsIdTXdJ8mAqJHY7rEPvV4Bb/J7trN+NGI6 XJII3MySpy/qNXAdvP2uIM14ZM1RQpZ+D9joDQM5ixqbIN/n0EaG6nhLiWH/fVTrZwqP UyB5sMPiJJ9SxRj40jPqW78QX7lpkfPP+ChusHJeDx+EEHJq+QJ/chjGAbgA3rxWoiy2 pGZ8lHD+5PyVwgE81vsHqyIWCvb1Bqe3pr38mI1CsDC2bFHV9X0Anj1gLEXm5G0+D9k2 V9pw== X-Gm-Message-State: AOJu0YxJLUqbSONEphGztGxR61Ff/nIaIVBrkyeU8H2615+gV1UPQQSG +M3IT35iNds4WX9HrMYP9CXLLqTsDrr2EkF4ZQI= X-Google-Smtp-Source: AGHT+IE/4dvBMK04/QM3dB45tEkBa7hhkGsxKWPjpZQyjkE/9XR9lCwdetlN6oGLYsCNMj0KFlgHaA== X-Received: by 2002:a05:6870:d183:b0:1fb:75b:9992 with SMTP id a3-20020a056870d18300b001fb075b9992mr8419565oac.65.1701790634712; Tue, 05 Dec 2023 07:37:14 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id y19-20020a02c013000000b00466a2a9e5b0sm3152510jai.32.2023.12.05.07.37.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 07:37:14 -0800 (PST) From: Tom Tromey Date: Tue, 05 Dec 2023 08:37:13 -0700 Subject: [PATCH 2/2] Refine Ada overload matching MIME-Version: 1.0 Message-Id: <20231205-ada-overload-v1-2-9d97ac80a60e@adacore.com> References: <20231205-ada-overload-v1-0-9d97ac80a60e@adacore.com> In-Reply-To: <20231205-ada-overload-v1-0-9d97ac80a60e@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Currently, the overload handling in Ada assumes that any two array types are compatible. However, this is obviously untrue, and a user reported an oddity where comparing two Ada strings resulted in a call to the "=" function for packed boolean arrays. This patch improves the situation somewhat, by requiring that the two arrays have the same arity and compatible base element types. This is still over-broad, but it seems safe and is better than the status quo. --- gdb/ada-lang.c | 45 ++++++++++++++++++++------- gdb/testsuite/gdb.ada/overloads.exp | 33 ++++++++++++++++++++ gdb/testsuite/gdb.ada/overloads/overloads.adb | 41 ++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 9d5c8d5534b..ac50ba5838c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3930,9 +3930,35 @@ ada_resolve_variable (struct symbol *sym, const struct block *block, return candidates[i]; } -/* Return non-zero if formal type FTYPE matches actual type ATYPE. */ -/* The term "match" here is rather loose. The match is heuristic and - liberal. */ +static bool ada_type_match (struct type *ftype, struct type *atype); + +/* Helper for ada_type_match that checks that two array types are + compatible. As with that function, FTYPE is the formal type and + ATYPE is the actual type. */ + +static bool +ada_type_match_arrays (struct type *ftype, struct type *atype) +{ + if (ftype->code () != TYPE_CODE_ARRAY + && !ada_is_array_descriptor_type (ftype)) + return false; + if (atype->code () != TYPE_CODE_ARRAY + && !ada_is_array_descriptor_type (atype)) + return false; + + if (ada_array_arity (ftype) != ada_array_arity (atype)) + return false; + + struct type *f_elt_type = ada_array_element_type (ftype, -1); + struct type *a_elt_type = ada_array_element_type (atype, -1); + return ada_type_match (f_elt_type, a_elt_type); +} + +/* Return non-zero if formal type FTYPE matches actual type ATYPE. + The term "match" here is rather loose. The match is heuristic and + liberal -- while it tries to reject matches that are obviously + incorrect, it may still let through some that do not strictly + correspond to Ada rules. */ static bool ada_type_match (struct type *ftype, struct type *atype) @@ -3970,18 +3996,15 @@ ada_type_match (struct type *ftype, struct type *atype) return false; } - case TYPE_CODE_ARRAY: - return (atype->code () == TYPE_CODE_ARRAY - || ada_is_array_descriptor_type (atype)); - case TYPE_CODE_STRUCT: - if (ada_is_array_descriptor_type (ftype)) - return (atype->code () == TYPE_CODE_ARRAY - || ada_is_array_descriptor_type (atype)); - else + if (!ada_is_array_descriptor_type (ftype)) return (atype->code () == TYPE_CODE_STRUCT && !ada_is_array_descriptor_type (atype)); + [[fallthrough]]; + case TYPE_CODE_ARRAY: + return ada_type_match_arrays (ftype, atype); + case TYPE_CODE_UNION: case TYPE_CODE_FLT: return (atype->code () == ftype->code ()); diff --git a/gdb/testsuite/gdb.ada/overloads.exp b/gdb/testsuite/gdb.ada/overloads.exp new file mode 100644 index 00000000000..41749a3774f --- /dev/null +++ b/gdb/testsuite/gdb.ada/overloads.exp @@ -0,0 +1,33 @@ +# Copyright 2021-2023 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile overloads + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/overloads.adb] +runto "overloads.adb:$bp_location" + +# Before the fix, these would show overload menus. +gdb_test "print Oload(PA)" " = 23" +gdb_test "print Oload(CA)" " = 91" diff --git a/gdb/testsuite/gdb.ada/overloads/overloads.adb b/gdb/testsuite/gdb.ada/overloads/overloads.adb new file mode 100644 index 00000000000..698d662712b --- /dev/null +++ b/gdb/testsuite/gdb.ada/overloads/overloads.adb @@ -0,0 +1,41 @@ +-- Copyright 2023 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +procedure Overloads is + + type Packed_Array is array (4 .. 7) of Boolean; + pragma pack (Packed_Array); + + type Char_Array is array (1 .. 4) of Character; + + function Oload (P : Packed_Array) return Integer is + begin + return 23; + end Oload; + + function Oload (C : Char_Array) return Integer is + begin + return 91; + end Oload; + + PA : Packed_Array := (True, False, True, False); + CA : Char_Array := ('A', 'B', 'C', 'D'); + + B1 : constant Integer := Oload (PA); + B2 : constant Integer := Oload (CA); + +begin + null; -- START +end Overloads;