diff mbox series

c: Fix C cast error-recovery [PR101171]

Message ID 20210624101123.GO7746@tucnak
State New
Headers show
Series c: Fix C cast error-recovery [PR101171] | expand

Commit Message

Jakub Jelinek June 24, 2021, 10:11 a.m. UTC
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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.


	Jakub

Comments

Marek Polacek June 24, 2021, 1:24 p.m. UTC | #1
On Thu, Jun 24, 2021 at 12:11:23PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> 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.

Yeah.
 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

This looks OK to me, thanks.
 
> 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.jj	2021-06-23 13:33:00.375434219 +0200
> +++ gcc/c/c-typeck.c	2021-06-23 17:51:17.501401208 +0200
> @@ -6131,6 +6131,7 @@ build_c_cast (location_t loc, tree type,
>       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);
>  
> --- gcc/testsuite/gcc.dg/pr101171.c.jj	2021-06-23 17:56:53.409896019 +0200
> +++ gcc/testsuite/gcc.dg/pr101171.c	2021-06-23 17:56:28.668227851 +0200
> @@ -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 ();
> +}
> 
> 	Jakub
> 

Marek
diff mbox series

Patch

--- gcc/c/c-typeck.c.jj	2021-06-23 13:33:00.375434219 +0200
+++ gcc/c/c-typeck.c	2021-06-23 17:51:17.501401208 +0200
@@ -6131,6 +6131,7 @@  build_c_cast (location_t loc, tree type,
      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);
 
--- gcc/testsuite/gcc.dg/pr101171.c.jj	2021-06-23 17:56:53.409896019 +0200
+++ gcc/testsuite/gcc.dg/pr101171.c	2021-06-23 17:56:28.668227851 +0200
@@ -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 ();
+}