Alexander Monakov <[email protected]> writes:
> Hello,
>
> thanks for sending this. A couple of typo callouts below:
>
> On Fri, 5 Jun 2026, Xi Ruoyao wrote:
>
>> So we don't make the same error again.
>> 
>> gcc/
>> 
>>      PR rtl-optimization/125609
>>      PR middle-end/122992
>>      * hard-reg-set.h
>>      (build_error_execute_if_set_in_hard_reg_temp_set): New
>
> Wrong name in parens.
>
>>      function.
>>      (EXECUTE_IF_SET_IN_HARD_REG_SET): Call the function above.
>> 
>> Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?
>> 
>> ---
>>  gcc/hard-reg-set.h | 14 ++++++++++++--
>>  1 file changed, 12 insertions(+), 2 deletions(-)
>> 
>> diff --git a/gcc/hard-reg-set.h b/gcc/hard-reg-set.h
>> index df56a3acedb..0465c5aab77 100644
>> --- a/gcc/hard-reg-set.h
>> +++ b/gcc/hard-reg-set.h
>> @@ -401,10 +401,20 @@ hard_reg_set_iter_next (hard_reg_set_iterator *iter, 
>> unsigned *)
>>    iter->bits &= ~ HARD_CONST (1);
>>  }
>>  
>> -/* SET must not change throughout the iteration.
>> +template <typename T>
>> +inline void
>> +build_error_on_rvalue (T &&)
>> +{
>> +  static_assert (!std::is_rvalue_reference<T&&>::value, "");
>> +}
>> +
>> +/* SET must not change throughout the iteration.  It's lifetime must
>
> "Its" (not "it's").
>
> Also, perhaps "Its lifetime must cover the entire loop" for clarity?

Agreed.  OK with those changes unless there are further comments in
the next 24hrs.

build_error_on_rvalue seems like it might be useful elsewhere in future,
but I can't think of a good "general" place to put it.  The closest I could
find was iterator-utils.h, but that's currently for C++-style iterators
rather than C-style iterators.

So I agree that it might as well stay in hard-reg-set.h until we have
more to go on.

This does show the benefit of C++-style iterators.  If we could just do:

  for (unsigned int regno : set)
    ...

then it would cope with temporary sets as well.  That said, I suppose
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#900 shows
that there are demons even there if (for example) we tried to define
derived iterators over subranges.

Richard

>
>> +   exceed the iteration so we call build_error_on_rvalue() to reject a
>> +   temporary object as SET.
>>     REGNUM (and ITER) may only be changed by the iteration functions.  */
>>  #define EXECUTE_IF_SET_IN_HARD_REG_SET(SET, MIN, REGNUM, ITER)          \
>> -  for (hard_reg_set_iter_init (&(ITER), (SET), (MIN), &(REGNUM));       \
>> +  for (build_error_on_rvalue (SET),                                     \
>> +       hard_reg_set_iter_init (&(ITER), (SET), (MIN), &(REGNUM));       \
>>         hard_reg_set_iter_set (&(ITER), &(REGNUM));                      \
>>         hard_reg_set_iter_next (&(ITER), &(REGNUM)))
>
> Alexander

Reply via email to