Patchwork [09/11] Fix va_arg type location

login
register
mail settings
Submitter Dodji Seketeli
Date April 11, 2012, 8:59 a.m.
Message ID <m3aa2i3api.fsf@redhat.com>
Download mbox | patch
Permalink /patch/151746/
State New
Headers show

Comments

Dodji Seketeli - April 11, 2012, 8:59 a.m.
Now that diagnostics first point to the spelling location of tokens
coming from macro expansion, the test case
gcc/testsuite/g++.old-deja/g++.other/vaarg3.C shows that when I write
va_args (args, some_type), the location that is recorded for
"some_type" is not correct.  We wrongly record a location that is in
the system header where the va_args macro is defined.

This patch changes that to correctly record the location for the type
operand of the va_arg expression.

With this patch applied, the
gcc/testsuite/g++.old-deja/g++.other/vaarg3.C test PASSes with and
without -ftrack-macro-expansion.

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

Note that the bootstrap with -ftrack-macro-expansion exhibits other
separate issues that are addressed in subsequent patches.  This patch
just fixes one class of problems.

The patch does pass bootstrap with -ftrack-macro-expansion turned off,
though.

gcc/cp/

	* cp-tree.h (build_x_va_arg): Take an additional location
	parameter.
	* call.c (build_x_va_arg): Take a loc parameter for the location
	of the type of the va_arg expression.
	* parser.c (cp_parser_primary_expression): Pass the type of the
	type in the va_arg expression to build_x_va_arg.
	* pt.c (tsubst_copy): Adjust calls to build_x_va_arg.
---
 gcc/cp/call.c    |    4 ++--
 gcc/cp/cp-tree.h |    2 +-
 gcc/cp/parser.c  |    4 +++-
 gcc/cp/pt.c      |    6 ++++--
 4 files changed, 10 insertions(+), 6 deletions(-)
Gabriel Dos Reis - April 11, 2012, 1:35 p.m.
On Wed, Apr 11, 2012 at 3:59 AM, Dodji Seketeli <dodji@redhat.com> wrote:
> Now that diagnostics first point to the spelling location of tokens
> coming from macro expansion, the test case
> gcc/testsuite/g++.old-deja/g++.other/vaarg3.C shows that when I write
> va_args (args, some_type), the location that is recorded for
> "some_type" is not correct.  We wrongly record a location that is in
> the system header where the va_args macro is defined.
>
> This patch changes that to correctly record the location for the type
> operand of the va_arg expression.
>
> With this patch applied, the
> gcc/testsuite/g++.old-deja/g++.other/vaarg3.C test PASSes with and
> without -ftrack-macro-expansion.
>
> Tested on x86_64-unknown-linux-gnu against trunk.
>
> Note that the bootstrap with -ftrack-macro-expansion exhibits other
> separate issues that are addressed in subsequent patches.  This patch
> just fixes one class of problems.
>
> The patch does pass bootstrap with -ftrack-macro-expansion turned off,
> though.

OK.

Patch

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index f2ea19b..6a26d6d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6073,7 +6073,7 @@  convert_arg_to_ellipsis (tree arg)
 /* va_arg (EXPR, TYPE) is a builtin. Make sure it is not abused.  */
 
 tree
-build_x_va_arg (tree expr, tree type)
+build_x_va_arg (source_location loc, tree expr, tree type)
 {
   if (processing_template_decl)
     return build_min (VA_ARG_EXPR, type, expr);
@@ -6099,7 +6099,7 @@  build_x_va_arg (tree expr, tree type)
       return expr;
     }
 
-  return build_va_arg (input_location, expr, type);
+  return build_va_arg (loc, expr, type);
 }
 
 /* TYPE has been given to va_arg.  Apply the default conversions which
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index db5e8a5..9dd7510 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4886,7 +4886,7 @@  extern void push_defarg_context			(tree);
 extern void pop_defarg_context			(void);
 extern tree convert_default_arg			(tree, tree, tree, int);
 extern tree convert_arg_to_ellipsis		(tree);
-extern tree build_x_va_arg			(tree, tree);
+extern tree build_x_va_arg			(source_location, tree, tree);
 extern tree cxx_type_promotes_to		(tree);
 extern tree type_passed_as			(tree);
 extern tree convert_for_arg_passing		(tree, tree);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index eac60f1..12cfdc1 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4168,6 +4168,7 @@  cp_parser_primary_expression (cp_parser *parser,
 	  {
 	    tree expression;
 	    tree type;
+	    source_location type_location;
 
 	    /* The `__builtin_va_arg' construct is used to handle
 	       `va_arg'.  Consume the `__builtin_va_arg' token.  */
@@ -4179,6 +4180,7 @@  cp_parser_primary_expression (cp_parser *parser,
 							  /*cast_p=*/false, NULL);
 	    /* Look for the `,'.  */
 	    cp_parser_require (parser, CPP_COMMA, RT_COMMA);
+	    type_location = cp_lexer_peek_token (parser->lexer)->location;
 	    /* Parse the type-id.  */
 	    type = cp_parser_type_id (parser);
 	    /* Look for the closing `)'.  */
@@ -4188,7 +4190,7 @@  cp_parser_primary_expression (cp_parser *parser,
 	    if (cp_parser_non_integral_constant_expression (parser,
 							    NIC_VA_ARG))
 	      return error_mark_node;
-	    return build_x_va_arg (expression, type);
+	    return build_x_va_arg (type_location, expression, type);
 	  }
 
 	case RID_OFFSETOF:
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ee38254..0c3f7c0 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12440,7 +12440,8 @@  tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       gcc_unreachable ();
 
     case VA_ARG_EXPR:
-      return build_x_va_arg (tsubst_copy (TREE_OPERAND (t, 0), args, complain,
+      return build_x_va_arg (EXPR_LOCATION (t),
+			     tsubst_copy (TREE_OPERAND (t, 0), args, complain,
 					  in_decl),
 			     tsubst (TREE_TYPE (t), args, complain, in_decl));
 
@@ -14273,7 +14274,8 @@  tsubst_copy_and_build (tree t,
       }
 
     case VA_ARG_EXPR:
-      return build_x_va_arg (RECUR (TREE_OPERAND (t, 0)),
+      return build_x_va_arg (EXPR_LOCATION (t),
+			     RECUR (TREE_OPERAND (t, 0)),
 			     tsubst (TREE_TYPE (t), args, complain, in_decl));
 
     case OFFSETOF_EXPR: