]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix ICE for invalid code with variadic and old-school prototypes [PR121507]
authorMartin Uecker <uecker@tugraz.at>
Sun, 21 Dec 2025 18:10:56 +0000 (19:10 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Sat, 3 Jan 2026 10:36:38 +0000 (11:36 +0100)
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.

gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/pr121507.c [new file with mode: 0644]

index fb17db4cb8ec685bb6d5498032eb4b445713ae7b..89ccf8205708863bb262b72a07faf0134fb2bb16 100644 (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))
            {
diff --git a/gcc/testsuite/gcc.dg/pr121507.c b/gcc/testsuite/gcc.dg/pr121507.c
new file mode 100644 (file)
index 0000000..2b9516a
--- /dev/null
@@ -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;
+}
+