https://gcc.gnu.org/g:2cb1108c0929311f73fc9210d29681ba49607b8d
commit r15-9918-g2cb1108c0929311f73fc9210d29681ba49607b8d Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Tue May 20 13:21:28 2025 -0700 middle-end: Fix complex lowering of cabs with no LHS [PR120369] This was introduced by r15-1797-gd8fe4f05ef448e . I had missed that the LHS of the cabs call could be NULL. This seems to only happen at -O0, I tried to produce one that happens at -O1 but needed many different options to prevent the removal of the call. Anyways the fix is just keep around the call if the LHS is null. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/120369 gcc/ChangeLog: * tree-complex.cc (gimple_expand_builtin_cabs): Return early if the LHS of cabs is null. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr120369-1.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> (cherry picked from commit 95c74f354ae3186e84fbada22d2e7f3845dbb659) Diff: --- gcc/testsuite/gcc.dg/torture/pr120369-1.c | 9 +++++++++ gcc/tree-complex.cc | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/gcc/testsuite/gcc.dg/torture/pr120369-1.c b/gcc/testsuite/gcc.dg/torture/pr120369-1.c new file mode 100644 index 000000000000..4c20fb0932f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr120369-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* PR middle-end/120369 */ + +/* Make sure cabs without a lhs does not cause an ICE. */ +void f() +{ + double _Complex z = 1.0; + __builtin_cabs(z); +} diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc index 8a812d4bf9b0..e339b3a5b377 100644 --- a/gcc/tree-complex.cc +++ b/gcc/tree-complex.cc @@ -1715,6 +1715,10 @@ gimple_expand_builtin_cabs (gimple_stmt_iterator *gsi, gimple *old_stmt) tree lhs = gimple_call_lhs (old_stmt); + /* If there is not a LHS, then just keep the statement around. */ + if (!lhs) + return; + real_part = extract_component (gsi, arg, false, true); imag_part = extract_component (gsi, arg, true, true); location_t loc = gimple_location (old_stmt);