]> gcc.gnu.org Git - gcc.git/commitdiff
Fix va_arg type location
authorDodji Seketeli <dodji@redhat.com>
Mon, 30 Apr 2012 11:42:50 +0000 (11:42 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Mon, 30 Apr 2012 11:42:50 +0000 (13:42 +0200)
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.

From-SVN: r186973

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/cp/pt.c

index 67dd067e867d55558c8e4acabc6f2422f00d460c..06edc5007b0bb24c1a94ada82b970b8a90e27764 100644 (file)
@@ -1,5 +1,14 @@
 2012-04-30  Dodji Seketeli  <dodji@redhat.com>
 
+       Fix va_arg type location
+       * 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.
+
        Make conversion warnings work on NULL with -ftrack-macro-expansion
        * call.c (conversion_null_warnings): Use the new
        expansion_point_location_if_in_system_header.
index 98d32c347e176d466732488598c442ae6aa0bbc4..e072891f9271c2c69d3d9f211ccbaed2e5afa235 100644 (file)
@@ -6133,7 +6133,7 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
 /* 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);
@@ -6159,7 +6159,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
index e046069182c2748169392246943f087d27711b8f..5a7ebaed9934909af2570ae8c456ea04f6822b01 100644 (file)
@@ -4891,7 +4891,7 @@ extern void pop_defarg_context                    (void);
 extern tree convert_default_arg                        (tree, tree, tree, int,
                                                 tsubst_flags_t);
 extern tree convert_arg_to_ellipsis            (tree, tsubst_flags_t);
-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, tsubst_flags_t);
index 3b5a476cdd05125c146ad74a96e74708ae835715..f0f7e987efb7352c6ec73c5425ec6bb63f2f2d9a 100644 (file)
@@ -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:
index 409e6b9cd52923dd4e823577dffc0c54f75a15fd..b720d4a3161f46639194602c0ea8daa90969b1f0 100644 (file)
@@ -12480,7 +12480,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));
 
@@ -14313,7 +14314,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:
This page took 0.115094 seconds and 5 git commands to generate.