c: Fix ICE for invalid code with variadic and old-school prototypes [PR121507]

When mixing old-school definition without prototype and new C23
variadic functions without named argument, there can be an ICE
when trying to form the composite type.  Avoid this by letting it
fail later due to incompatible types.

	PR c/121507

gcc/c/ChangeLog:
	* c-decl.cc (start_function): Adapt condition.

gcc/testsuite/ChangeLog:
	* gcc.dg/pr121507.c: New test.
This commit is contained in:
Martin Uecker
2025-12-21 19:10:56 +01:00
committed by Martin Uecker
parent 41177976c5
commit b46e4afaff
2 changed files with 12 additions and 1 deletions

View File

@@ -10787,7 +10787,8 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
tree newrt = TREE_TYPE (newtype);
if (old_decl != NULL_TREE
&& TREE_CODE (oldtype) == FUNCTION_TYPE
&& comptypes (oldrt, newrt))
&& comptypes (oldrt, newrt)
&& !TYPE_NO_NAMED_ARGS_STDARG_P (oldtype))
{
if (stdarg_p (oldtype))
{

View File

@@ -0,0 +1,10 @@
/* { dg-do compile } */
/* { dg-options "-std=c23" } */
int * xmalloc(...);
int * xmalloc(n) /* { dg-error "conflicting types" } */
int n; /* { dg-warning "old-style function definition" "" { target *-*-* } .-1 } */
{
return 0;
}