https://gcc.gnu.org/g:20c529f47542e94e921556684f8ce27495135926

commit r17-1439-g20c529f47542e94e921556684f8ce27495135926
Author: Xi Ruoyao <[email protected]>
Date:   Fri Jun 5 16:29:20 2026 +0800

    hard-reg-set: make temporary SET for EXECUTE_IF_SET_IN_HARD_REG_SET a 
build-time error
    
    So we don't make the same error again.
    
    gcc/
    
            PR rtl-optimization/125609
            PR middle-end/122992
            * hard-reg-set.h
            (build_error_on_rvalue): New function.
            (EXECUTE_IF_SET_IN_HARD_REG_SET): Call the function above.

Diff:
---
 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 df56a3acedb1..9685f117f9b6 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.  Its lifetime must cover
+   the entire loop 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)))

Reply via email to