This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/30457] Please warn about va_start(ap, invalid)
- From: "manu at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Nov 2007 15:32:06 -0000
- Subject: [Bug c/30457] Please warn about va_start(ap, invalid)
- References: <bug-30457-1038@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from manu at gcc dot gnu dot org 2007-11-03 15:32 -------
What about this patch? Does it look correct?
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c (revision 129513)
+++ gcc/builtins.c (working copy)
@@ -11357,6 +11357,29 @@
it. */
warning (0, "second parameter of %<va_start%> not last named
argument");
}
+
+ /* Undefined by C99 7.15.1.4p4 (va_start):
+ "If the parameter parmN is declared with the register storage
+ class, with a function or array type, or with a type that is
+ not compatible with the type that results after application of
+ the default argument promotions, the behavior is undefined."
+ */
+ if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE)
+ {
+ warning (0, "undefined behaviour when second parameter of "
+ "%<va_start%> is declared of function type");
+ }
+ else if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
+ {
+ warning (0, "undefined behaviour when second parameter of "
+ "%<va_start%> is declared of array type");
+ }
+ else if (DECL_REGISTER (arg))
+ {
+ warning (0, "undefined behaviour when second parameter of "
+ "%<va_start%> is declared with %<register%> storage");
+ }
+
/* We want to verify the second parameter just once before the tree
optimizers are run and then avoid keeping it in the tree,
as otherwise we could warn even for correct code like:
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457