public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8057] c: Error on va_arg with function type [PR105149]
@ 2022-04-08  7:17 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-04-08  7:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6e2743687202c58a6553ae632ebbada3de38ad48

commit r12-8057-g6e2743687202c58a6553ae632ebbada3de38ad48
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 8 09:16:30 2022 +0200

    c: Error on va_arg with function type [PR105149]
    
    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.

Diff:
---
 gcc/c/c-typeck.cc               |  6 ++++++
 gcc/testsuite/gcc.dg/pr105149.c | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6c4af5e4cde..e130196a3a7 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -15896,6 +15896,12 @@ c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type)
 		"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%>");
diff --git a/gcc/testsuite/gcc.dg/pr105149.c b/gcc/testsuite/gcc.dg/pr105149.c
new file mode 100644
index 00000000000..b748f454d6d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105149.c
@@ -0,0 +1,16 @@
+/* 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);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-08  7:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08  7:17 [gcc r12-8057] c: Error on va_arg with function type [PR105149] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).