[Bug c/30457] Please warn about va_start(ap, invalid)
manu at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat Nov 3 15:32:00 GMT 2007
------- 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
More information about the Gcc-bugs
mailing list