From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id C8yAFIsHeWk6YRgAWB0awg (envelope-from ) for ; Tue, 27 Jan 2026 13:44:27 -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=GGuynqq9; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 417781E0DD; Tue, 27 Jan 2026 13:44:27 -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 63BCE1E08D for ; Tue, 27 Jan 2026 13:44:26 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id CC3F44BA23F3 for ; Tue, 27 Jan 2026 18:44:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC3F44BA23F3 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=GGuynqq9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3F9534BA2E06 for ; Tue, 27 Jan 2026 18:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F9534BA2E06 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 3F9534BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769539439; cv=none; b=W4vIIACY4TX9n3lObcibS9TZGeuUaYKdJacfsEzJBSeTmLRJupyOUt5f+evZ01Vnn2mZ5ZwvERY5CUyjqD688VGY0saeyNdTYjC42FvfrhqRtSwk1xJNRVZJump6oxRaWMY5mM9QD++yTI8Lx+Dx0+sCuF4IQTg/mYhRcJsHZSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769539439; c=relaxed/simple; bh=BYcsItrPG/VW1/Vlimpfs8WtWbdDGfaCIsq0q5764d4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=S/dJB3YT5C4sILyy9lUeELHDOeYL+JUo7Ezr6KtX8f8eXN0YrruQCAfvBFgEDgl1dabPoZCL97+ZxN9VKd4fPCBKVMG2VH02rzlzGXq6YQJqhXFmjKICOJUCpTVeKvMnFXHmI0xZCvSGxn05CABurhmFKyplBdLPGnEYE/+njSQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F9534BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769539438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lswqSUgI4TWzWMsHaPNkLTiJYyOMoLMCp+JzEkiAmcc=; b=GGuynqq95q+ilGmRxDZ4dBj2v4b5i4a+HqLDL1HRzEdo4466yOB6nINWGh8ZqqssbnY190 5/ht609Vc0tm5fshK9zS+v2BJ97fjuo1cztJajavBM4yiivt4wpCvvPGjuowSeBYNEH2lL Ckz4ib5qTw5d28qZKHtK7SoOckDIM1E= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-403-l3mNZj-jPIKcfZoMtkaMhQ-1; Tue, 27 Jan 2026 13:43:57 -0500 X-MC-Unique: l3mNZj-jPIKcfZoMtkaMhQ-1 X-Mimecast-MFC-AGG-ID: l3mNZj-jPIKcfZoMtkaMhQ_1769539437 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2a7701b6353so59680315ad.3 for ; Tue, 27 Jan 2026 10:43:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769539436; x=1770144236; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lswqSUgI4TWzWMsHaPNkLTiJYyOMoLMCp+JzEkiAmcc=; b=lkfViK7kYaJWnZlwWkue7CPgmcbQfCrWOBFN7nLT+wBqWOyn/k6JWEWVOWKlJavvq7 gpFZ4q1B+UYmYnLKytXVLENKVfxhh1QeGpDzpl05plVBiaiz0LMAOHrmxsUoWlLmb+4Q ibHzzEoVX/E4JLBisKIbIaBNTQinvkY9WVTKwSqBvlNf/UJ+ZEDEoVgUdZneW2/edXSB 8r+HaUjbyAB5RcwQPcGLTAt384spSBmpCr34qsTX7Z619z435FE/NzQoCBDsVJTLR/9C YCw8jEVjkQips8Tj1gYlwTCeohobTD+4V+UiV6mKPTcj//0Wmaz/FEZu2eycrKOc7tcI 0UvQ== X-Forwarded-Encrypted: i=1; AJvYcCWkxetVy4h4ri4JyiAOIS4nUopAreqBEqwPQMJmL10PHMESkKK4c2MJ7IhihR0U8eMuDThagOfR1ts22w==@sourceware.org X-Gm-Message-State: AOJu0Yys4JQwsZcp7gzQq+RkNOZ/Yu3aAB7qgRkC9xTcX3DemEtq+9Gs RE3EOEFf647dhyT9rk7xK/JQ7PNRDTtWRZ2B+R9/Jt4HS6i0UpJM7ezmoGDBAWUjsthkI20QRHZ KtXce66hXWePY31uCRLSiroTSMZrxy1HdzLIBPlz42at/Fpsimx26Sd1dXodvEcYTUAZk9Ts= X-Gm-Gg: AZuq6aJfz2sznGYnX8ioVHaRPR27qB2+JCKCoOEpoCfHZpqZsDWuAEICtyrXgcnMUfw pRYKMjZll1wjaqLJLMzBCu4xLyhEYR+l7T6CZSJQwKeuCklAD4gpYORs+3EDSOk47l5KkFWjAAx DhPgQdKdvW6BfATXfpqmveUpqCg5RQVqlJnGqp4z1MZMGykApPcdJSL0WHOp8FVgLykKAU0gspR Z/E8k04OZSOy9ARBYvD4W/DQhO7LY1SbXDi3KshbXiLfMlEtcFSXRJCV1RB78EEs1Dg7cwByYLL mS0i0dRf4vS/KTrT0wxlbbDMzLAuc++T/V3fBa1blrAYCaddxPPazzXhw8ytjSJQyM8ID+TZB8a BfEhNuahbgYEHcYsx X-Received: by 2002:a17:903:1585:b0:2a7:80ac:85b0 with SMTP id d9443c01a7336-2a870da13bdmr24119045ad.2.1769539436279; Tue, 27 Jan 2026 10:43:56 -0800 (PST) X-Received: by 2002:a17:903:1585:b0:2a7:80ac:85b0 with SMTP id d9443c01a7336-2a870da13bdmr24118955ad.2.1769539435921; Tue, 27 Jan 2026 10:43:55 -0800 (PST) Received: from [150.1.200.157] ([172.56.106.185]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a88b5d9e25sm693135ad.80.2026.01.27.10.43.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jan 2026 10:43:55 -0800 (PST) Message-ID: Date: Tue, 27 Jan 2026 10:43:54 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] infcall: Add support for integer literals as reference function paramters To: "Aktemur, Tankut Baris" , "gdb-patches@sourceware.org" References: <87qzuvcfb1.fsf@redhat.com> <8eca9443ad95346c52e5e4bec71eb44ba173f0c0.1769104412.git.keiths@redhat.com> From: Keith Seitz In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -oVnvB9AoNRv1WyEScLC1GjaXnboGCDiJensofTQeVw_1769539437 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 Hi! On 1/23/26 6:07 AM, Aktemur, Tankut Baris wrote: > On Thursday, January 22, 2026 8:06 PM, Keith Seitz wrote: >> diff --git a/gdb/infcall.c b/gdb/infcall.c >> index dcbae679d07..b836a868d15 100644 >> --- a/gdb/infcall.c >> +++ b/gdb/infcall.c >> @@ -276,10 +276,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. For C++ reference parameters, >> + if the value is not already in memory (e.g., a literal), we >> + need to allocate space in the inferior and copy the value there. >> + If the value is already in memory, we can use its address >> + directly. */ >> new_value = value_cast (type->target_type (), arg); >> + if (new_value->lval () != lval_memory >> + && language_pass_by_reference (new_value->type ()) >> + .trivially_copyable) >> + { >> + LONGEST length = check_typedef (new_value->type ())->length (); >> + struct value *addr_val = value_allocate_space_in_inferior >> (length); > > This uses malloc to allocate the space. I was wondering if allocating > space on the stack wouldn't be better. That's how arguments that are > implicitly pass-by-reference are passed. Also struct return values > are forced to lval in stack-allocated memory. > > Furthermore, malloc would not be possible everywhere (e.g. on GPUs); > stack allocation would be supported by more platforms. > > There is gdbarch_reserve_stack_space to allocate space on stack, > but it needs to be passed the current stack pointer. I don't know > how easy it is to get and set the SP in this context. Yes, I think we can use stack for this -- a lot of call_function_by_hand_dummy does this already. I've made this change. >> + CORE_ADDR addr = value_as_address (addr_val); >> + write_memory (addr, new_value->contents ().data (), length); >> + new_value = value_at_lazy (new_value->type (), addr); > > IMHO, we could use > > CORE_ADDR addr = allocate_space_in_inferior (length); // Or stack space. > new_value->force_lval (addr); I've made this change. >> diff --git a/gdb/testsuite/gdb.cp/ref-params.exp >> b/gdb/testsuite/gdb.cp/ref-params.exp >> index b61055e9f50..a94927fae56 100644 >> --- a/gdb/testsuite/gdb.cp/ref-params.exp >> +++ b/gdb/testsuite/gdb.cp/ref-params.exp [snip] >> +gdb_test "print const_ref_func(global_obj)" \ >> + "= 20" \ >> + "call function with const ref param and global object" > > Another potentially interesting testcase would be passing > a "literal" object, like this: > > print const_ref_func((TestClass) {42}) > > This case is also fixed with your patch. I've added these tests. > >> +# Test functions taking non-const reference parameter. >> +gdb_test "print ref_func(10)" \ >> + "Cannot resolve function ref_func to any overloaded instance" \ >> + "call function with non-const ref param and literal" >> + >> +gdb_test "print ref_func(global_int)" \ >> + " = 43" \ >> + "call function with non-const ref param and global variable" >> + >> +gdb_test "print ref_func(local_var)" \ >> + " = 16" \ >> + "call function with non-const ref param and local variable" >> + >> +gdb_test "print ref_func(obj)" \ >> + "= 6" \ >> + "call function with non-const ref param and object" >> + >> +gdb_test "print ref_func(global_obj)" \ >> + "= 11" \ >> + "call function with non-const ref param and global object" >> + >> +# Test methods taking constant reference parameter. >> +gdb_test "print obj.const_ref_method(5)" \ >> + "= 10" \ >> + "call const method with const ref param and literal" >> + >> +gdb_test "print obj.const_ref_method(global_int)" \ >> + "= 47" \ >> + "call const method with const ref param and global variable" >> + >> +gdb_test "print obj.const_ref_method(local_var)" \ >> + "= 20" \ >> + "call const method with const ref param and local variable" >> + >> +gdb_test "print obj.const_ref_method (obj)" \ > > Nit: The other tests don't have space before parenthesis. > You are correct, and trailing parentheses are not permitted in test names like this (or used to anyway). I've corrected this typo. Good eye! [snip] >> +gdb_test "print global_obj.ref_method(global_obj)" \ >> + "= 30" \ >> + "call global method with non-const ref param and global object" >> \ No newline at end of file > > Could you please add a new line at the end? Done. I will send v4 [note I have an off-by-one error in my versioning]. Thank you for your review! Keith