public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30457] New: Please warn about va_start(ap, invalid)
@ 2007-01-13 18:48 h dot b dot furuseth at usit dot uio dot no
2007-11-03 15:20 ` [Bug c/30457] " manu at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: h dot b dot furuseth at usit dot uio dot no @ 2007-01-13 18:48 UTC (permalink / raw)
To: gcc-bugs
Here is some undefined behavior which it would be nice if gcc
warned about, since stdarg is such a hairy part of the standard:
#include <stdarg.h>
void foo(register short paramN, ...)
{
va_list ap;
va_start(ap, paramN); // 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."
// gcc does warn about the following, undefined by C99 7.15.1.1p2:
(void) va_arg(ap, char);
// "warning: 'char' is promoted to 'int' when passed through '...'
// warning: (so you should pass 'int' not 'char' to 'va_arg')
// note: if this code is reached, the program will abort"
va_end(ap);
}
--
Summary: Please warn about va_start(ap, invalid)
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: h dot b dot furuseth at usit dot uio dot no
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/30457] Please warn about va_start(ap, invalid)
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
@ 2007-11-03 15:20 ` manu at gcc dot gnu dot org
2007-11-03 15:32 ` manu at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-11-03 15:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from manu at gcc dot gnu dot org 2007-11-03 15:20 -------
This check could be implemented in builtins.c (fold_builtin_next_arg).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/30457] Please warn about va_start(ap, invalid)
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
2007-11-03 15:20 ` [Bug c/30457] " manu at gcc dot gnu dot org
@ 2007-11-03 15:32 ` manu at gcc dot gnu dot org
2008-08-21 19:08 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-11-03 15:32 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/30457] Please warn about va_start(ap, invalid)
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
2007-11-03 15:20 ` [Bug c/30457] " manu at gcc dot gnu dot org
2007-11-03 15:32 ` manu at gcc dot gnu dot org
@ 2008-08-21 19:08 ` manu at gcc dot gnu dot org
2008-08-21 19:13 ` manu at gcc dot gnu dot org
2008-08-21 19:13 ` manu at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-21 19:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from manu at gcc dot gnu dot org 2008-08-21 19:07 -------
Subject: Bug 30457
Author: manu
Date: Thu Aug 21 19:05:46 2008
New Revision: 139406
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139406
Log:
2008-08-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 30457
* builtins.c (fold_builtin_next_arg): Add warning about undefined
behaviour.
testsuite/
* gcc.dg/pr30457.c: New.
Added:
trunk/gcc/testsuite/gcc.dg/pr30457.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/30457] Please warn about va_start(ap, invalid)
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
` (3 preceding siblings ...)
2008-08-21 19:13 ` manu at gcc dot gnu dot org
@ 2008-08-21 19:13 ` manu at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-21 19:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2008-08-21 19:12 -------
Thanks for the report!
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/30457] Please warn about va_start(ap, invalid)
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
` (2 preceding siblings ...)
2008-08-21 19:08 ` manu at gcc dot gnu dot org
@ 2008-08-21 19:13 ` manu at gcc dot gnu dot org
2008-08-21 19:13 ` manu at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-21 19:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from manu at gcc dot gnu dot org 2008-08-21 19:12 -------
We warn now about "register", the other cases are not warned following the
rationale given here:
http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00819.html
Fixed in GCC 4.4
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30457
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-08-21 19:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-13 18:48 [Bug c/30457] New: Please warn about va_start(ap, invalid) h dot b dot furuseth at usit dot uio dot no
2007-11-03 15:20 ` [Bug c/30457] " manu at gcc dot gnu dot org
2007-11-03 15:32 ` manu at gcc dot gnu dot org
2008-08-21 19:08 ` manu at gcc dot gnu dot org
2008-08-21 19:13 ` manu at gcc dot gnu dot org
2008-08-21 19:13 ` manu at gcc dot gnu dot org
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).