From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CI2wODYVemlU3xkAWB0awg (envelope-from ) for ; Wed, 28 Jan 2026 08:55:02 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjX5GArn; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C93461E08D; Wed, 28 Jan 2026 08:55:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8DC771E08D for ; Wed, 28 Jan 2026 08:55:01 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id EE4A24BAD141 for ; Wed, 28 Jan 2026 13:55:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE4A24BAD141 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gjX5GArn Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 04F2C4BA2E27 for ; Wed, 28 Jan 2026 13:54:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04F2C4BA2E27 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 04F2C4BA2E27 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=1769608475; cv=none; b=I0SxX8rRqKzKPIFCwkx4GAgPMRooTxJrx5ZHRsMAe3JvccV9TIzFTPppvCgzraRG2b+vSfMXWQUfgq7sqCsqR3BvzHDWjfqKp3kmgBsSAsXhjHpNBIVfiQOTjYHxU4474ONxJYr+9HcqEF2ESDaVEPw1Xy6w7TLJK/5tcZvHMY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769608475; c=relaxed/simple; bh=06+2FwH/D+1efANnAw3FdLdMyPxZ8DEQlOtqmRpfsCA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bWerlPMZXGycuQFzVcolP2vXjMOpbdDm2I8ojqZuVup48/WnW/IpMAoWkc76Q17bxcZ4Zf0xhv6Xt3Gnw27YiY8SkoOX2qxOf0qlVtPjPAocbHx8xwY6H33/PFicM3/uXrfL/mdZdQatXm7qFoxSDrhJNeklRBE1E1Qcntj5lSs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 04F2C4BA2E27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769608474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+p65hO6x/YciEmvyzW7YuEvTE+L7rhjQklXJNS9181k=; b=gjX5GArngUHymCwTIDaWIAqsHY73lAyDdZ7cP+kgZR9Grtt5K4F26L3t89Kl0cichjYnpj QLt1sQsX41/02hGLwloD37th3yGecTMb3yX1Hvfu0OZZ8aK0OhECnK9CdIq03zZMqpdMcG OJsN6BTO4l0At+uIpLLmWrREZ54fXwI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-GX1-ofHgOxKbFanICvavAg-1; Wed, 28 Jan 2026 08:54:33 -0500 X-MC-Unique: GX1-ofHgOxKbFanICvavAg-1 X-Mimecast-MFC-AGG-ID: GX1-ofHgOxKbFanICvavAg_1769608472 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48057c39931so42429135e9.0 for ; Wed, 28 Jan 2026 05:54:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769608472; x=1770213272; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+p65hO6x/YciEmvyzW7YuEvTE+L7rhjQklXJNS9181k=; b=WM1e88CIr4xc+I6o9D5LJZly8eYA5J7mgNq9OH55cGpnGO/LhCQcZ+IZCDga7MzlRb ehJBkeaou/AgcpNUrDrgbazY0w3rbl+ikofWyf77rS8xRhPPi3BwZ2fmJa7kriNMmB9j PoGkQjEe7KnFjYnB0n/7E3uUDHL7UOxr0G2OynSJJhIcm2oH5UPkUgUy2EAwI+IBp3M1 Dqc0eAPF0r+iL7+pG+PV06cGBUX4vHx91eR6sOgiCv1ssbWNfu30MXF1LL0ervxBZicC yYnFwJj2weM9EeGKF/EhSMB/aAG1HZx2ikJFZondc+MB2ObCy7MckpcjbkVgukK7wLz2 8AyQ== X-Forwarded-Encrypted: i=1; AJvYcCUhTA3XY5pBbYt2x6fOZHJyWNJM+jmADmpdMeaej9Q78+KP0sJgVGM388jeTeOwHCNjINaHCRIeztxLlw==@sourceware.org X-Gm-Message-State: AOJu0Yw9JNY9ToupIZHJPyOp02tcVK2EaYfvpwsYrzQhn86ezCPjWD1C lNqboh40cG/BSpeyZV8iUKBeWKMSOaaEmyFhRYRhAbF9Fk5o66jikpXYLWG+aXKD9Ee2iaoBwLw +Zy3ILdQrJ/CWmIuPoQ32ID5UP2BvVyeioHAvKJHEOJVH0MouepSVHEEcTPDuVeo= X-Gm-Gg: AZuq6aIv/PT/FJ6RDv6YixSr5Q7ysdXMIY1EzlZ5vS3xYEgNxu27OvJMIGH2M7WNHeP AstFCOBSO4kEU2xA3RRTqFJCmGQ04RlESXM3+Es+6THhWqEBmz53frknFRdZBP3Jr8RHgoS9G8S 2AgWBz7PksUZ9JP+x6xNrwgKeIl066/d8x19zlNZ4FImzXHLuNKXC5bJdquUuqOja4Anre7EUNL SBdwnRIGbXN3gOsD1fl3305c0w5hAVUDhYm6wps9oqT98s/glXI2QZjPQBNp+yMu8fe105Ffdlw uqqf/YtUIkqpSIJvCWGxsQCw85rKbozaYudIWbzOa554SEv33Q8FptWe7iSR3rHc9iBcjUZNS/l wc7bF X-Received: by 2002:a05:600d:8445:20b0:47d:3ffa:5f03 with SMTP id 5b1f17b1804b1-48069c54b8bmr55895225e9.21.1769608471945; Wed, 28 Jan 2026 05:54:31 -0800 (PST) X-Received: by 2002:a05:600d:8445:20b0:47d:3ffa:5f03 with SMTP id 5b1f17b1804b1-48069c54b8bmr55895025e9.21.1769608471449; Wed, 28 Jan 2026 05:54:31 -0800 (PST) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4806df6056esm24197735e9.2.2026.01.28.05.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 05:54:31 -0800 (PST) From: Andrew Burgess To: Keith Seitz , gdb-patches@sourceware.org Subject: Re: [PATCH v4] infcall: Add support for integer literals as reference function paramters In-Reply-To: <963c933a79455dc4aaa35f8c34bed8693065e6a5.1769539110.git.keiths@redhat.com> References: <92575c2eb6805095b41ebbe62ba99b81e4e5dd63.1760629738.git.keiths@redhat.com> <963c933a79455dc4aaa35f8c34bed8693065e6a5.1769539110.git.keiths@redhat.com> Date: Wed, 28 Jan 2026 13:54:30 +0000 Message-ID: <87h5s5g7vt.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zLQLLvIU0blWdcRYTVrWStHZys_jHf7PEvST5hUaaQM_1769608472 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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~public-inbox=simark.ca@sourceware.org Keith Seitz writes: > This patch attempts to mitigate the shortcomings of passing literals > to inferior function calls requiring references. The specific use case here > is std::map's operator[]: > > std::map int_map; > int_map[1] = 10; > (gdb) print int_map[1] > Attempt to take address of value not located in memory. > > This is occurring because while value_coerce_to_target understands > that some values need to be allocated and copied to the inferior's > memory, it only considers the actual parsed type of the argument value, > ignoring the actual type of the function parameter. That is, > in this specific case, the value's parsed type is TYPE_CODE_INT, but > the function requires TYPE_CODE_REF. We need to account for the > reference. > > In value_arg_coerce, we have special handling for references, but it > has not specifically dealt with this case. It now checks if the > reference is in memory, and if it isn't, it copies it, if the type > is trivially copyable. > > As a result of this patch, the last remaining failure in c++/15372 is now > fixed, and that bug can be closed. > > With this patch, we can now print map entries with integer keys: > > (gdb) print int_map[1] > $1 = (std::map, std::allocator > >::mapped_type &) @0x41f2d4: 10 > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15372 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25957 > > Changes in v4 > - Allocate to stack instead of heap I'm interested by this change. Within value_arg_coerce, a few lines before your change, there's this comment: /* Force the value to the target if we will need its address. At this point, we could allocate arguments on the stack instead of calling malloc if we knew that their addresses would not be saved by the called function. */ arg = value_coerce_to_target (arg); I don't believe there's anything stopping the inferior function taking the address of the reference argument and storing it. Could you explain this change a little more? > - Use value::force_lval to simply copying to inferior memory > - Add some addition tests > > Changes in v3 > - Move logic to value_arg_coerce > - Add some attempt to limit copying to trivially copyable types > --- > gdb/infcall.c | 26 +++- > gdb/testsuite/gdb.cp/ref-params.cc | 95 +++++++++++- > gdb/testsuite/gdb.cp/ref-params.exp | 146 +++++++++++++++++++ > gdb/testsuite/gdb.cp/rvalue-ref-overload.exp | 1 - > 4 files changed, 261 insertions(+), 7 deletions(-) > > diff --git a/gdb/infcall.c b/gdb/infcall.c > index dcbae679d07..c4e9605a665 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -63,6 +63,8 @@ static bool debug_infcall = false; > #define INFCALL_SCOPED_DEBUG_START_END(fmt, ...) \ > scoped_debug_start_end (debug_infrun, "infcall", fmt, ##__VA_ARGS__) > > +static CORE_ADDR reserve_stack_space (const type *values_type, CORE_ADDR &sp); > + > /* Implement 'show debug infcall'. */ > > static void > @@ -246,7 +248,8 @@ show_unwind_on_timeout_p (struct ui_file *file, int from_tty, > > static struct value * > value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, > - struct type *param_type, int is_prototyped) > + struct type *param_type, int is_prototyped, > + CORE_ADDR *sp, struct thread_info *call_thread) > { > const struct builtin_type *builtin = builtin_type (gdbarch); > struct type *arg_type = check_typedef (arg->type ()); > @@ -276,10 +279,23 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, > return value_cast_pointers (type, arg, 0); > > /* Cast the value to the reference's target type, and then > - convert it back to a reference. This will issue an error > - if the value was not previously in memory - in some cases > - we should clearly be allowing this, but how? */ > + convert it back to a reference. If the value is not already > + in memory (e.g., a literal), we need to allocate space in the > + inferior and copy it there. */ > new_value = value_cast (type->target_type (), arg); > + if (new_value->lval () != lval_memory > + && language_pass_by_reference (new_value->type ()) > + .trivially_copyable) > + { > + CORE_ADDR addr; > + > + gdb_assert (sp != nullptr); Given reserve_stack_space expects a reference to a CORE_ADDR, I think I'd just make the argument to this function 'CORE_ADDR &sp', then this assert can be dropped. Thanks, Andrew