c: Avoid clobbering TREE_TYPE (error_mark_node) [PR99990]

The following testcase ICEs during error recovery, because finish_decl
overwrites TREE_TYPE (error_mark_node), which better should stay always
to be error_mark_node.

2021-04-10  Jakub Jelinek  <jakub@redhat.com>

	PR c/99990
	* c-decl.c (finish_decl): Don't overwrite TREE_TYPE of
	error_mark_node.

	* gcc.dg/pr99990.c: New test.
This commit is contained in:
Jakub Jelinek 2021-04-10 17:01:54 +02:00
parent 0344b5b822
commit 9f7d77bd6d
2 changed files with 13 additions and 1 deletions

View File

@ -5402,7 +5402,7 @@ finish_decl (tree decl, location_t init_loc, tree init,
gcc_unreachable ();
}
if (DECL_INITIAL (decl))
if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
TREE_TYPE (DECL_INITIAL (decl)) = type;
relayout_decl (decl);

View File

@ -0,0 +1,12 @@
/* PR c/99990 */
/* { dg-do compile } */
/* { dg-options "" } */
#include <stdarg.h>
void
foo ()
{
va_arg (0, long); /* { dg-error "first argument to 'va_arg' not of type 'va_list'" } */
void *b[] = 0; /* { dg-error "invalid initializer" } */
}