https://gcc.gnu.org/g:c180ad35fb695ee4797bf9c5cb8a292c7af6b358

commit r16-5136-gc180ad35fb695ee4797bf9c5cb8a292c7af6b358
Author: Andrew Pinski <[email protected]>
Date:   Fri Nov 7 21:08:42 2025 -0800

    builtins: Fix atomics expansion after build_call_nary change [PR122605]
    
    So before r16-5089-gc66ebc3e22138, we could call build_call_nary with more
    arguments than was passed as the nargs. Afterwards we get an assert if there
    were not exactly that amount.
    In this case the code is easier to read when passing the correct number of 
args
    in the first place.
    This fixes the two places in builtins.cc where this pattern shows up.
    
    Bootstrapped and tested on x86_64-linux-gnu (and tested the testcase with 
-m32 where
    the failure showed up).
    
            PR middle-end/122605
    gcc/ChangeLog:
    
            * builtins.cc (expand_ifn_atomic_bit_test_and): Split out the call 
to
            build_call_nary into two different statements.
            (expand_ifn_atomic_op_fetch_cmp_0): Likewise.
    
    Signed-off-by: Andrew Pinski <[email protected]>

Diff:
---
 gcc/builtins.cc | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index fb294ce58cd4..bbe181a51288 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -7076,11 +7076,13 @@ expand_ifn_atomic_bit_test_and (gcall *call)
       tree tcall = gimple_call_arg (call, 3 + is_atomic);
       tree fndecl = gimple_call_addr_fndecl (tcall);
       tree type = TREE_TYPE (TREE_TYPE (fndecl));
-      tree exp = build_call_nary (type, tcall, 2 + is_atomic, ptr,
-                                 make_tree (type, val),
-                                 is_atomic
-                                 ? gimple_call_arg (call, 3)
-                                 : integer_zero_node);
+      tree exp;
+      if (is_atomic)
+       exp = build_call_nary (type, tcall, 3,
+                              ptr, make_tree (type, val),
+                              gimple_call_arg (call, 3));
+      else
+       exp = build_call_nary (type, tcall, 2, ptr, make_tree (type, val));
       result = expand_builtin (exp, gen_reg_rtx (mode), NULL_RTX,
                               mode, !lhs);
     }
@@ -7184,11 +7186,13 @@ expand_ifn_atomic_op_fetch_cmp_0 (gcall *call)
       tree tcall = gimple_call_arg (call, 3 + is_atomic);
       tree fndecl = gimple_call_addr_fndecl (tcall);
       tree type = TREE_TYPE (TREE_TYPE (fndecl));
-      tree exp = build_call_nary (type, tcall,
-                                 2 + is_atomic, ptr, arg,
-                                 is_atomic
-                                 ? gimple_call_arg (call, 3)
-                                 : integer_zero_node);
+      tree exp;
+      if (is_atomic)
+       exp = build_call_nary (type, tcall, 3,
+                              ptr, arg,
+                              gimple_call_arg (call, 3));
+      else
+       exp = build_call_nary (type, tcall, 2, ptr, arg);
       result = expand_builtin (exp, gen_reg_rtx (mode), NULL_RTX,
                               mode, !lhs);
     }

Reply via email to