c++: Fix error recovery ICE [PR112365]

Message ID ZUfUB5r2Y7J3GPbv@tucnak
State Unresolved
Headers
Series c++: Fix error recovery ICE [PR112365] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Nov. 5, 2023, 5:42 p.m. UTC
  Hi!

check_field_decls for DECL_C_BIT_FIELD FIELD_DECLs with error_mark_node
TREE_TYPE continues early and doesn't call check_bitfield_decl which would
either set DECL_BIT_FIELD, or clear DECL_C_BIT_FIELD.  So, the following
testcase ICEs after emitting tons of errors, because
SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD asserts DECL_BIT_FIELD.

The patch skips that for FIELD_DECLs with error_mark_node, another
option would be to check DECL_BIT_FIELD in addition to DECL_C_BIT_FIELD.

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

2023-11-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/112365
	* class.cc (layout_class_type): Don't
	SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD on FIELD_DECLs with
	error_mark_node type.

	* g++.dg/cpp0x/pr112365.C: New test.


	Jakub
  

Comments

Jason Merrill Nov. 16, 2023, 2:59 p.m. UTC | #1
On 11/5/23 12:42, Jakub Jelinek wrote:
> Hi!
> 
> check_field_decls for DECL_C_BIT_FIELD FIELD_DECLs with error_mark_node
> TREE_TYPE continues early and doesn't call check_bitfield_decl which would
> either set DECL_BIT_FIELD, or clear DECL_C_BIT_FIELD.  So, the following
> testcase ICEs after emitting tons of errors, because
> SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD asserts DECL_BIT_FIELD.
> 
> The patch skips that for FIELD_DECLs with error_mark_node, another
> option would be to check DECL_BIT_FIELD in addition to DECL_C_BIT_FIELD.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2023-11-05  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/112365
> 	* class.cc (layout_class_type): Don't
> 	SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD on FIELD_DECLs with
> 	error_mark_node type.
> 
> 	* g++.dg/cpp0x/pr112365.C: New test.
> 
> --- gcc/cp/class.cc.jj	2023-11-04 09:02:35.380001476 +0100
> +++ gcc/cp/class.cc	2023-11-04 10:03:34.974075429 +0100
> @@ -6962,7 +6962,8 @@ layout_class_type (tree t, tree *virtual
>   	     check_bitfield_decl eventually sets DECL_SIZE (field)
>   	     to that width.  */
>   	  && (DECL_SIZE (field) == NULL_TREE
> -	      || integer_zerop (DECL_SIZE (field))))
> +	      || integer_zerop (DECL_SIZE (field)))
> +	  && TREE_TYPE (field) != error_mark_node)
>   	SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
>         check_non_pod_aggregate (field);
>       }
> --- gcc/testsuite/g++.dg/cpp0x/pr112365.C.jj	2023-11-04 10:05:58.285013791 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/pr112365.C	2023-11-04 10:05:14.879638217 +0100
> @@ -0,0 +1,8 @@
> +// PR c++/112365
> +// { dg-do compile { target c++11 } }
> +// { dg-excess-errors "" }
> +
> +template <typename> struct A;
> +template <typename T> A <T> foo (T;
> +template <typename T> struct A { constexpr A : T {} }
> +struct { bar ( { foo (this)
> 
> 	Jakub
>
  

Patch

--- gcc/cp/class.cc.jj	2023-11-04 09:02:35.380001476 +0100
+++ gcc/cp/class.cc	2023-11-04 10:03:34.974075429 +0100
@@ -6962,7 +6962,8 @@  layout_class_type (tree t, tree *virtual
 	     check_bitfield_decl eventually sets DECL_SIZE (field)
 	     to that width.  */
 	  && (DECL_SIZE (field) == NULL_TREE
-	      || integer_zerop (DECL_SIZE (field))))
+	      || integer_zerop (DECL_SIZE (field)))
+	  && TREE_TYPE (field) != error_mark_node)
 	SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
       check_non_pod_aggregate (field);
     }
--- gcc/testsuite/g++.dg/cpp0x/pr112365.C.jj	2023-11-04 10:05:58.285013791 +0100
+++ gcc/testsuite/g++.dg/cpp0x/pr112365.C	2023-11-04 10:05:14.879638217 +0100
@@ -0,0 +1,8 @@ 
+// PR c++/112365
+// { dg-do compile { target c++11 } }
+// { dg-excess-errors "" }
+
+template <typename> struct A;
+template <typename T> A <T> foo (T;
+template <typename T> struct A { constexpr A : T {} }
+struct { bar ( { foo (this)