]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: Fix complex lowering of cabs with no LHS [PR120369]
authorAndrew Pinski <quic_apinski@quicinc.com>
Tue, 20 May 2025 20:21:28 +0000 (13:21 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 21 May 2025 04:32:44 +0000 (21:32 -0700)
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_apinski@quicinc.com>
gcc/testsuite/gcc.dg/torture/pr120369-1.c [new file with mode: 0644]
gcc/tree-complex.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr120369-1.c b/gcc/testsuite/gcc.dg/torture/pr120369-1.c
new file mode 100644 (file)
index 0000000..4c20fb0
--- /dev/null
@@ -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);
+}
index 8a812d4bf9b0b3e971cd4853eac6d12522ebf600..e339b3a5b377f30fe7debc32376d2ce0412246e1 100644 (file)
@@ -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);