]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix gimplification ICE for shifts with invalid redeclarations
authorJoseph Myers <josmyers@redhat.com>
Thu, 28 Nov 2024 02:41:35 +0000 (02:41 +0000)
committerJoseph Myers <josmyers@redhat.com>
Thu, 28 Nov 2024 02:41:35 +0000 (02:41 +0000)
As reported in bug 117757, there is a C gimplification ICE for shifts
involving a variable that was incompatibly redeclared (and thus had
its type changed to error_mark_node).  Fix this with an appropriate
error_operand_p check.

Note that this is not the same issue as any of the other bugs reported
for ICEs later in the gimplifier dealing with such erroneous
redeclarations (it is, however, the same as the *second* ICE reported
in bug 115644 - the test in comment#1 for that bug, not the one in the
original bug report).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/117757

gcc/c-family/
* c-gimplify.cc (c_gimplify_expr): Check for error_operand_p
before calling TYPE_MAIN_VARIANT for shifts.

gcc/testsuite/
* gcc.dg/pr117757-1.c: New test.

gcc/c-family/c-gimplify.cc
gcc/testsuite/gcc.dg/pr117757-1.c [new file with mode: 0644]

index 09ea1b79159070e2323544c2d8482589a0447b18..d4b97b4a97288f6a99dcbcd4b54671a854933ab5 100644 (file)
@@ -806,7 +806,8 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
           We should get rid of this conversion when we have a proper
           type demotion/promotion pass.  */
        tree *op1_p = &TREE_OPERAND (*expr_p, 1);
-       if (!VECTOR_TYPE_P (TREE_TYPE (*op1_p))
+       if (!error_operand_p (*op1_p)
+           && !VECTOR_TYPE_P (TREE_TYPE (*op1_p))
            && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
                                    unsigned_type_node)
            && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
diff --git a/gcc/testsuite/gcc.dg/pr117757-1.c b/gcc/testsuite/gcc.dg/pr117757-1.c
new file mode 100644 (file)
index 0000000..238b6db
--- /dev/null
@@ -0,0 +1,10 @@
+/* Test ICE for shift with invalid redeclaration (bug 117757).  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int a)
+{
+  1 << a;
+  int a[1]; /* { dg-error "redeclared" } */
+}