Re: [PATCH v5] infcall: Add support for integer literals as reference function parameters

Keith Seitz
2026-03-12T16:46:05Z

Hi,

On 3/12/26 9:23 AM, Tom de Vries wrote:
> On 3/12/26 3:14 PM, Keith Seitz wrote:
>> This is v5 of my attempt to add simple integer literal support for
>> refernece
>
> Hi Keith,
>
> refernece -> reference

Wowser. I'm blaming a lack of caffeine on all of this.

Please ignore this revision -- I will repost with all the typos fixed.
[And I noticed I forgot to revert some additional changes to
value_arg_coerce...]

> Also, I applied the test-case from this patch ( https://sourceware.org/
> pipermail/gdb-patches/2024-November/213340.html ) and confirmed that it
> also passes with this patch.
>
> I'm not sure if that means that you can claim the corresponding PR as
> well, or if it means that the test-case I wrote was not representive of
> the PR.

I am sorry I completely missed that. We seem to have come to two
different solutions. I will investigate and follow-up in my v6 repost.

>
>> how a user (or their program) handles any of these values.
>>
>> Keith
>>
>> Changes in v5
>> - Return to heap allocation
>>
>> Changes in v4
>> - Allocate to stack instead of heap
>> - 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
>>
>> -----
>>
>> 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, int>;
>> 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,
>
>> Changes in v5
>> - After reconsideration, return to heap allocation
>>
>> Changes in v4
>> - Allocate to stack instead of heap
>> - 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
>
> Is this a pasto?  The list seems to be in the middle of some text.

<cough>It certainly is.</cough>

Thank you for taking a look!
Keith