From patchwork Wed Apr 11 08:59:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 151746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9B83FB705E for ; Wed, 11 Apr 2012 19:00:20 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1334739620; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=ZMF7mukpBPk5bZpkUBaEHDO693o=; b=ElZtxISVtx/Rpoa0ifQKDu9OY9I4+z0MxrzyYlKAkLiV+A5KoEfux1Yk/XceGT sDREDL4v6/wtpq+/56irjKpPcolMK+CLvgbgo/g0bo9lSaUAywLE6+uDCv3RXFz/ 9k0OS2wIub/sgBBdHsuNHqtcJOZZWDXp38JHLSRNrLE+g= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YJZpr6+MMuzc2n1gaQFLhaKieWnBrXpHALG60+86YDIISOHq9R4yANQJAfUOsz hA+D3Clz15Q+nH4Zl4uzfO5mDfw5AVOUIcN6kxoofSp42QNRWLrg5Ifjxlbpy7xl HOKBbp++mVSZf43mxeBsNvaIOsoy0NGJmkx68LMI1layM=; Received: (qmail 31584 invoked by alias); 11 Apr 2012 09:00:16 -0000 Received: (qmail 31575 invoked by uid 22791); 11 Apr 2012 09:00:14 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Apr 2012 08:59:56 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3B8xt7q017974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Apr 2012 04:59:55 -0400 Received: from localhost (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3B8xsbQ028264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Apr 2012 04:59:55 -0400 Received: by localhost (Postfix, from userid 500) id 9BF7229C046; Wed, 11 Apr 2012 10:59:53 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Tom Tromey , Jason Merrill , Gabriel Dos Reis Subject: [PATCH 09/11] Fix va_arg type location References: X-URL: http://www.redhat.com Date: Wed, 11 Apr 2012 10:59:53 +0200 In-Reply-To: (Dodji Seketeli's message of "Tue, 10 Apr 2012 16:53:12 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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(-) 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: