]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins: Fix atomics expansion after build_call_nary change [PR122605]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 8 Nov 2025 05:08:42 +0000 (21:08 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 10 Nov 2025 18:20:10 +0000 (10:20 -0800)
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 <andrew.pinski@oss.qualcomm.com>
gcc/builtins.cc

index fb294ce58cd4bfa2e2d1b074a54bf52ce355db10..bbe181a51288675d5bcc7df14396f3c2eea9364d 100644 (file)
@@ -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);
     }