Commit 34c88790 by Dodji Seketeli Committed by Dodji Seketeli

Fix va_start related location

In gcc/testsuite/gcc.dg/pr30457.c, the first warning was not being
emitted because the relevant location was inside the var_start macro
defined in a system header.  It can even point to a token for a
builtin macro there.  This patch unwinds to the first token in real
source code in that case.

Tested on x86_64-unknown-linux-gnu against trunk.

	* builtins.c (fold_builtin_next_arg): Unwinds to the first
	location in real source code.

From-SVN: r186975
parent bfd93a72
2012-04-30 Dodji Seketeli <dodji@redhat.com> 2012-04-30 Dodji Seketeli <dodji@redhat.com>
Fix va_start related location
* builtins.c (fold_builtin_next_arg): Unwinds to the first
location in real source code.
Make conversion warnings work on NULL with -ftrack-macro-expansion Make conversion warnings work on NULL with -ftrack-macro-expansion
* input.h (expansion_point_location_if_in_system_header): Declare * input.h (expansion_point_location_if_in_system_header): Declare
new function. new function.
......
...@@ -12095,6 +12095,13 @@ fold_builtin_next_arg (tree exp, bool va_start_p) ...@@ -12095,6 +12095,13 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
tree fntype = TREE_TYPE (current_function_decl); tree fntype = TREE_TYPE (current_function_decl);
int nargs = call_expr_nargs (exp); int nargs = call_expr_nargs (exp);
tree arg; tree arg;
/* There is good chance the current input_location points inside the
definition of the va_start macro (perhaps on the token for
builtin) in a system header, so warnings will not be emitted.
Use the location in real source code. */
source_location current_location =
linemap_unwind_to_first_non_reserved_loc (line_table, input_location,
NULL);
if (!stdarg_p (fntype)) if (!stdarg_p (fntype))
{ {
...@@ -12119,7 +12126,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p) ...@@ -12119,7 +12126,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
{ {
/* Evidently an out of date version of <stdarg.h>; can't validate /* Evidently an out of date version of <stdarg.h>; can't validate
va_start's second argument, but can still work as intended. */ va_start's second argument, but can still work as intended. */
warning (0, "%<__builtin_next_arg%> called without an argument"); warning_at (current_location,
0,
"%<__builtin_next_arg%> called without an argument");
return true; return true;
} }
else if (nargs > 1) else if (nargs > 1)
...@@ -12154,7 +12163,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p) ...@@ -12154,7 +12163,9 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
argument. We just warn and set the arg to be the last argument. We just warn and set the arg to be the last
argument so that we will get wrong-code because of argument so that we will get wrong-code because of
it. */ it. */
warning (0, "second parameter of %<va_start%> not last named argument"); warning_at (current_location,
0,
"second parameter of %<va_start%> not last named argument");
} }
/* Undefined by C99 7.15.1.4p4 (va_start): /* Undefined by C99 7.15.1.4p4 (va_start):
...@@ -12164,8 +12175,12 @@ fold_builtin_next_arg (tree exp, bool va_start_p) ...@@ -12164,8 +12175,12 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
the default argument promotions, the behavior is undefined." the default argument promotions, the behavior is undefined."
*/ */
else if (DECL_REGISTER (arg)) else if (DECL_REGISTER (arg))
warning (0, "undefined behaviour when second parameter of " {
"%<va_start%> is declared with %<register%> storage"); warning_at (current_location,
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 /* We want to verify the second parameter just once before the tree
optimizers are run and then avoid keeping it in the tree, optimizers are run and then avoid keeping it in the tree,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment