]> gcc.gnu.org Git - gcc.git/commitdiff
c: Fix C cast error-recovery [PR101171]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Jun 2021 13:55:28 +0000 (15:55 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 24 Jun 2021 13:55:28 +0000 (15:55 +0200)
The following testcase ICEs during error-recovery, as build_c_cast calls
note_integer_operands on error_mark_node and that wraps it into
C_MAYBE_CONST_EXPR which is unexpected and causes ICE later on.
Seems most other callers of note_integer_operands check early if something
is error_mark_node and return before calling note_integer_operands on it.

The following patch fixes it by not calling on error_mark_node, another
possibility would be to handle error_mark_node in note_integer_operands and
just return it.

2021-06-24  Jakub Jelinek  <jakub@redhat.com>

PR c/101171
* c-typeck.c (build_c_cast): Don't call note_integer_operands on
error_mark_node.

* gcc.dg/pr101171.c: New test.

gcc/c/c-typeck.c
gcc/testsuite/gcc.dg/pr101171.c [new file with mode: 0644]

index d0d36c3b0818229917f51155106cb82e69f77324..d079ce4b05bb05eb34200799e7b514d76fbf3cf1 100644 (file)
@@ -6131,6 +6131,7 @@ build_c_cast (location_t loc, tree type, tree expr)
      return value reflects this.  */
   if (int_operands
       && INTEGRAL_TYPE_P (type)
+      && value != error_mark_node
       && !EXPR_INT_CONST_OPERANDS (value))
     value = note_integer_operands (value);
 
diff --git a/gcc/testsuite/gcc.dg/pr101171.c b/gcc/testsuite/gcc.dg/pr101171.c
new file mode 100644 (file)
index 0000000..8d2bcab
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c/101171 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern void foo (void);
+int x = 0x1234;
+
+void
+bar (void)
+{
+  if (x != (sizeof ((enum T) 0x1234))) /* { dg-error "conversion to incomplete type" } */
+    foo ();
+}
This page took 0.081995 seconds and 5 git commands to generate.