In the PR Joseph said that the C standard for va_arg talks about
pointers to object type and as a function type is not object type,
it is invalid.
The following patch diagnoses it in the FE, instead of ICEing later on
when optimizations are turned on (and with -O0 doing something weird
at runtime).
2022-04-08 Jakub Jelinek <jakub@redhat.com>
PR c/105149
* c-typeck.cc (c_build_va_arg): Reject function types.
* gcc.dg/pr105149.c: New test.
"type %qT", type);
return error_mark_node;
}
+ else if (TREE_CODE (type) == FUNCTION_TYPE)
+ {
+ error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
+ type);
+ return error_mark_node;
+ }
else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
warning_at (loc2, OPT_Wc___compat,
"C++ requires promoted type, not enum type, in %<va_arg%>");
--- /dev/null
+/* PR c/105149 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include <stdarg.h>
+
+void
+foo (int s, ...)
+{
+ int e;
+ va_list ap;
+
+ va_start (ap, s);
+ e = va_arg (ap, int (void)) (); /* { dg-error "second argument to 'va_arg' is a function type" } */
+ va_end (ap);
+}