]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimplify: Allow declarations in recalculate_side_effects [PR126497]
authorJakub Jelinek <jakub@redhat.com>
Fri, 31 Jul 2026 07:05:50 +0000 (09:05 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 31 Jul 2026 07:05:50 +0000 (09:05 +0200)
The following testcase ICEs, because we decide to fold a comparison
into just one of its operands, we call recalculate_side_effects on that
and ICE on the assertion that it isn't called on anything unexpected
(here PARM_DECL).
Already some time ago we had to add an exception for SSA_NAME for the
same reason.
The tcc_declaration case is slightly different, TREE_SIDE_EFFECTS is
sometimes present on those if they are TREE_THIS_VOLATILE, but it is
something the FE should take care of when creating those decls, not
a business of the gimplifier.

2026-07-31  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/126497
* gimplify.cc (recalculate_side_effects): Return for
tcc_declaration.

* gcc.dg/bitint-141.c: New test.

Reviewed-by: Andrea Pinski <andrew.pinski@oss.qualcomm.com>
gcc/gimplify.cc
gcc/testsuite/gcc.dg/bitint-141.c [new file with mode: 0644]

index 333e0a3f3a9aed1743d20d752c4c43c367769212..0f8bf533ba756b8f90371ffc2df2bba9bbb0c59c 100644 (file)
@@ -3361,6 +3361,13 @@ recalculate_side_effects (tree t)
       /* No side-effects.  */
       return;
 
+    case tcc_declaration:
+      /* These can have side-effects if TREE_THIS_VOLATILE,
+        but those should be set elsewhere, not in
+        recalculate_side_effects.  Can be triggered e.g. if
+        a comparison is folded into one of its operands.  */
+      return;
+
     default:
       if (code == SSA_NAME)
        /* No side-effects.  */
diff --git a/gcc/testsuite/gcc.dg/bitint-141.c b/gcc/testsuite/gcc.dg/bitint-141.c
new file mode 100644 (file)
index 0000000..f3f22bb
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR middle-end/126497 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23" } */
+
+typedef unsigned _BitInt (1) U;
+
+U
+foo (U a)
+{
+  U t = a >= 1uwb;
+  return t;
+}
+
+U
+bar (U a)
+{
+  U t = a == 1uwb;
+  return t;
+}