https://gcc.gnu.org/g:f42bbef5c0a66881ec2fd41ab3ac3e2860080018
commit r16-7973-gf42bbef5c0a66881ec2fd41ab3ac3e2860080018 Author: Andrew Pinski <[email protected]> Date: Mon Mar 9 15:38:33 2026 -0700 c: Fix ICE after an error: typedef and old style prototypes for nested functions [PR123461] This started to ICE after r16-3747-gafa74d37e8170d which added a call to mark_decl_used. You can't call mark_decl_used with a typedef which is an error mark as you get an ICE. There is a check right after the newly added call for error mark, so let's move the call to inside that block instead. Bootstrapped and tested on x86_64-linux-gnu. PR c/123461 gcc/c/ChangeLog: * c-decl.cc (declspecs_add_type): Move mark_decl_used call after the check for error mark node. gcc/testsuite/ChangeLog: * gcc.dg/pr123461-1.c: New test. Signed-off-by: Andrew Pinski <[email protected]> Diff: --- gcc/c/c-decl.cc | 2 +- gcc/testsuite/gcc.dg/pr123461-1.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 10b4d77daee4..98249b922695 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -13065,10 +13065,10 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs, error_at (loc, "two or more data types in declaration specifiers"); else if (TREE_CODE (type) == TYPE_DECL) { - mark_decl_used (type, false); specs->type = TREE_TYPE (type); if (TREE_TYPE (type) != error_mark_node) { + mark_decl_used (type, false); specs->decl_attr = DECL_ATTRIBUTES (type); specs->typedef_p = true; specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); diff --git a/gcc/testsuite/gcc.dg/pr123461-1.c b/gcc/testsuite/gcc.dg/pr123461-1.c new file mode 100644 index 000000000000..d94932bd2d81 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr123461-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ +/* PR c/123461 */ + +void foo(int n) { + enum b typedef V[]; /* { dg-error "array type has incomplete element type" } */ + void bar(V) /* { dg-error "old-style parameter" } */ + V bar_ptr; + {} +}
