From: Martin Uecker Date: Sun, 21 Dec 2025 18:10:56 +0000 (+0100) Subject: c: Fix ICE for invalid code with variadic and old-school prototypes [PR121507] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b46e4afaff5b2cfd23b6d4d364d12f3f7ec07f78;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index fb17db4cb8e..89ccf820570 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -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)) { diff --git a/gcc/testsuite/gcc.dg/pr121507.c b/gcc/testsuite/gcc.dg/pr121507.c new file mode 100644 index 00000000000..2b9516aaffe --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121507.c @@ -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; +} +