From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id saQ8NK/I+GjJ3wIAWB0awg (envelope-from ) for ; Wed, 22 Oct 2025 08:06:07 -0400 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=Ir0TylJe; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C669D1E04C; Wed, 22 Oct 2025 08:06:07 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 0E1611E04C for ; Wed, 22 Oct 2025 08:06:02 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 679AD3858405 for ; Wed, 22 Oct 2025 12:06:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 679AD3858405 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=Ir0TylJe 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 4E62B3858C66 for ; Wed, 22 Oct 2025 12:05:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E62B3858C66 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 4E62B3858C66 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=1761134727; cv=none; b=YvPiGWSKZOWOyNrWgCQft04nQbLgB617PH/WVeeCwdzcrwI4sn+aZ7hBrwccAs0Y0dEAhAPglKvOS2/K7QqmqzqQO+tJMGAi1ujwwapBmVI05+65D4zB8xHPhehJb9b5L7WxJn4JAo5Sl41KUBhCdQVHK802JCG9JdulrRmizBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761134727; c=relaxed/simple; bh=h9eXxrK428ctJBKlIizMeoWDY08UWnk7kYLX9Z2TB0c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XUt3DjWynDGi7XAZbVZRoZtY1da2zpGWOPv++Ap+Z1kI+rGKneD4ErmjZS8Ak5Ssb1ZGE0dPu78Wm9oyVpGdwkDJt2su5EPFziBfWt9SLzh0w9GVxuoN49XJxjPeXJHnmNcw7uxceOYlHCWVqmsz3Qw0pgAcZa6VdzWqTZ3ze+8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E62B3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761134727; 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: in-reply-to:in-reply-to:references:references; bh=Ol+Fk5YqQP0q1JibB8oJrFXCskqJHGue1tpwjG2quTk=; b=Ir0TylJePFhFNSWoTP8TjJtWMdZ2XT1fce88UFA+RoHkssFx8DAR2svKs1baijmC1oFOZB r7RveAEAYwSmrUDxQGN0peO0XOEs3iFWTLXiBlaqQ0VkFoValNbGwMSug/Owujred5Kkpx 2VxE3Kky+lozT8gaTWf6w2DS5iqzpBA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-oLLeKJAKPZioPXPP9BdYqg-1; Wed, 22 Oct 2025 08:05:25 -0400 X-MC-Unique: oLLeKJAKPZioPXPP9BdYqg-1 X-Mimecast-MFC-AGG-ID: oLLeKJAKPZioPXPP9BdYqg_1761134724 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-471201dc0e9so56848155e9.2 for ; Wed, 22 Oct 2025 05:05:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761134724; x=1761739524; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ol+Fk5YqQP0q1JibB8oJrFXCskqJHGue1tpwjG2quTk=; b=LL00zvfyAkAAs6E+t1oE4cPUCYdtmbeDugl0GLc8zPkPjlzWK34mQSaPm56vTuoV19 ybYbJZaV6HGE3KH+UiWn30ZPkbAVdkAGHQMg2w3SYOm5RBcID3ZNrJbBeMHT5Pl/0u+G rydsDYJETOU1Dcscp9uzZjmuxWhBj+1xyjA2stS35NDSRwW6WXbj122eJO0naqwv18Dw B0tRs3AZjdYOoEHcCqYRvT6cU2q7H7JxEToWjUie+ko020hqZWCh+Y363aryyTiyPaQZ vNBnBUuNV/ArLjrxc9XoDa5+ia+uDBtwGPeUsTGSnFlwbI9Kptpph+k/cm3ZJtD/3pU9 U7Gg== X-Gm-Message-State: AOJu0YytJPHhTjXHESlmy/ZtXGjMx8NaR5FhDuvzw9IYJ0fhQL9zjFki DpWpvLD6dUtOj43V+x6UhYX8i2bbF2NRtDyt50M3xkVxVW0Vg3mMfEvRy8mxpsLagHfwGtDUIat C521XQq9woc2fdynJJJMFz+vf9LCvlE8BRQsVI6aChLWb7SXFoh1oPxIJ3GPzPdQ= X-Gm-Gg: ASbGnct76zuw97CxKYXOQOKB1Z3yuFP/dVVmzDrzb5Jn4Gs1j9GF8/aWUpQAZfX9kvF TMcyEhg5YjNAxQSa3alQSdUGN7jTYty3aLs5L7c5B3Xpbm9QQZ5uPIglE5nH7TyqCd7WBu0iEOv ngTESSevEX16lnvzVJhr0NKnwXF0JQsojZRadsCFI5yHmNAgLA4+SSKEYAv+/Z1iwikjZfjtI+B 40p+lJ7vlrPpZIuNZHvhAJTQpOLMwchmySOxxAoVkjYMmDIk4NtuQi6qoT4isx0xB4ZlnFaNYQN PAxfJLJXSFjOqYcnNYoK75edbuGT3VK632MEcjuoPaQYLpCljeI2cjj8fCAW+YJ+Oei44Q== X-Received: by 2002:a05:600c:820f:b0:471:176d:bf8a with SMTP id 5b1f17b1804b1-4711791cd3dmr165113735e9.35.1761134724434; Wed, 22 Oct 2025 05:05:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVh28Abm6TAPqcaRN1aZ3NtGoQFbEA12rCoIjl2ml7T+KbZnU38mJO+LabkcofHuJCaXBCug== X-Received: by 2002:a05:600c:820f:b0:471:176d:bf8a with SMTP id 5b1f17b1804b1-4711791cd3dmr165113345e9.35.1761134723898; Wed, 22 Oct 2025 05:05:23 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-475c428dafesm40009135e9.6.2025.10.22.05.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Oct 2025 05:05:23 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , Keith Seitz Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2] infcall: Add support for integer literals as reference function paramters In-Reply-To: <877bwom2ip.fsf@tromey.com> References: <92575c2eb6805095b41ebbe62ba99b81e4e5dd63.1760629738.git.keiths@redhat.com> <877bwom2ip.fsf@tromey.com> Date: Wed, 22 Oct 2025 13:05:22 +0100 Message-ID: <87qzuvcfb1.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: HnMXb-bihNBbiHjAdvrl_sULX1sTIA_M9uGTtk3J3jw_1761134724 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 Tom Tromey writes: >>>>>> "Keith" == Keith Seitz writes: > > Keith> This patch attempts to mitigate the shortcomings of passing literals > Keith> to inferior function calls requiring references. The specific use case here > Keith> is std::map's operator[]: > > Thanks for doing this. > > Keith> struct value * > Keith> -value_coerce_to_target (struct value *val) > Keith> +value_coerce_to_target (struct value *val, struct type *param_type) > Keith> { > > I wasn't totally sold on doing the work here and not in value_arg_coerce > but I guess it makes sense. > > Keith> + if (param_type != nullptr && param_type->language () == language_cplus > Keith> + && TYPE_IS_REFERENCE (param_type)) > Keith> + { > > Can we get here with a value that has an address, and so we don't need > to make a copy? Like if there's a local variable 'x', and you do 'print > map[x]'? I took a look at this patch too, and came here to say the same thing. In fact, this is exactly why the 'param_type->language () == language_cplus' is needed. The Fortran breakage that Keith mentions does this: (gdb) p return_string(returned_string_debugger, 40) (gdb) p returned_string_debugger The first line calls 'return_string' passing in the inferior variable 'returned_string_debugger' (length 40), the function is then going to fill that variable in for us, which we print on the next line. Without the 'param_type->language() == language_cplus' bit, we end up creating a copy of 'returned_string_debugger' in the inferior, which the 'return_string' function fills in. Then back in GDB we try to print the original variable, which _hasn't_ been filled in. This is all just a long way around of saying that Tom's right. > If the argument is already in memory, then just casting its address to a > reference would be a lot better, especially because memcpy()ing the data > into the inferior is only really correct for trivially-copyable types. I agree with this. This function `value_coerce_to_target` does seem like a sensible place to update to fix this, but given that the forcing seems to be entangled with the parameter type, I wonder if this should be fixed back in `value_arg_coerce` (infcall.c)? Specifically, in this block: case TYPE_CODE_REF: case TYPE_CODE_RVALUE_REF: { struct value *new_value; if (TYPE_IS_REFERENCE (arg_type)) 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? */ new_value = value_cast (type->target_type (), arg); new_value = value_ref (new_value, type->code ()); return new_value; } The comment seems (to me) to hint at the exact problem that you are trying to solve here. Maybe the solution is to split `value_coerce_to_target` and `value_must_coerce_to_target` into some smaller pieces and then reuse those within `value_arg_coerce`? > I don't know if that property (trivially-copyable) is all that easy to > detect in gdb, but if it is, I guess it would make sense to detect it > and throw an exception. Since in that case we'd be looking at something > like a callee that wants memory but where the object has been SROA'd or > something along those lines. We have `language_pass_by_reference`, the return value of which will, I think, tell you if a type is trivially-copyable or not. I don't think this is going to be the common path though; don't objects that are not trivially-copyable have to live in memory? I'm sure there might be some edge case here, but for me, I'd be happy with a patch that ignores this for now, and we can come back to this later if/when we find a problematic case. Thanks, Andrew