From patchwork Tue Apr 10 14:57:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 151611 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 BC51EB7021 for ; Wed, 11 Apr 2012 00:57:46 +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=1334674667; 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=9KtCK9gVWlqaPl6P1oa2/BRvVRc=; b=dxf79HoLeFAnjCeGY8ROzAS0Qxewxtxd1sjFIYZz49qZL9ClQ9scNyDRZA0Pv0 5HfplngUYmdRXq1LYNrPBXLGn2NVxNV396saJ7U1s67ljVXBHhyWuemkfY4k6zf6 b+aysZWlCL6eN5Xt6AAR/StVt1irEkGzQejy76DKnO3d0= 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=rdzW7XqRfQ6TQOB4/zv7/tkBVyGCzmf+lfYpy3k2cnmDcNy3uK5Fll45+GzCuM TIOif/kHoYFyAaom/xHo03B/KgDbFbxnbtyoieOLzy2UrUQpuTxNmwbbkZdqGGtg 76+fNDgGfwf6XY4NZe4Huvy6y+DPAU0j8M89ewkABsQtg=; Received: (qmail 1815 invoked by alias); 10 Apr 2012 14:57:32 -0000 Received: (qmail 1699 invoked by uid 22791); 10 Apr 2012 14:57:30 -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; Tue, 10 Apr 2012 14:57:16 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3AEvFop019516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Apr 2012 10:57:15 -0400 Received: from localhost (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3AEvEvV012104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 Apr 2012 10:57:15 -0400 Received: by localhost (Postfix, from userid 500) id BBAE329C046; Tue, 10 Apr 2012 16:57:13 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Tom Tromey , Jason Merrill , Gabriel Dos Reis Subject: [PATCH 02/11] Fix token pasting with -ftrack-macro-expansion References: X-URL: http://www.redhat.com Date: Tue, 10 Apr 2012 16:57:13 +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 This patch makes token pasting work with -ftrack-macro-expansion turned on. It improves some pasting related tests of the gcc.dg/cpp sub-directory. Tested and bootstrapped 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. libcpp/ * macro.c (paste_all_tokens): Put the token resulting from pasting into an extended token context with -ftrack-macro-location is in effect. gcc/testsuite/ * gcc.dg/cpp/paste17.c: New test case for -ftrack-macro-expansion=2 mode only. * gcc.dg/cpp/macro-exp-tracking-5.c: Likewise. --- gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c | 18 ++++++++++++++ gcc/testsuite/gcc.dg/cpp/paste17.c | 8 ++++++ libcpp/macro.c | 28 ++++++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c create mode 100644 gcc/testsuite/gcc.dg/cpp/paste17.c diff --git a/gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c b/gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c new file mode 100644 index 0000000..7933660 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/macro-exp-tracking-5.c @@ -0,0 +1,18 @@ +/* + { dg-options "-fshow-column -ftrack-macro-expansion" } + { dg-do compile } + */ + +#define PASTED var ## iable /* { dg-error "undeclared" } */ +#define call_foo(p1, p2) \ + foo (p1, \ + p2); /* { dg-message "in expansion of macro" } */ + +void foo(int, char); + +void +bar() +{ + call_foo(1,PASTED); /* { dg-message "expanded from here" } */ +} + diff --git a/gcc/testsuite/gcc.dg/cpp/paste17.c b/gcc/testsuite/gcc.dg/cpp/paste17.c new file mode 100644 index 0000000..9c6506f --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/paste17.c @@ -0,0 +1,8 @@ + /* { dg-options "-ftrack-macro-expansion=2" } */ +/* { dg-do preprocess } */ + +#define do_paste 1.0e ## -1 + +do_paste + +/* { dg-final {scan-file paste17.i "1.0e- 1" } }*/ diff --git a/libcpp/macro.c b/libcpp/macro.c index 58a722c..e0bfc31 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -611,6 +611,21 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs) { const cpp_token *rhs = NULL; cpp_context *context = pfile->context; + source_location virt_loc = 0; + + /* We must have been called on a token that appears at the left + hand side of a ## operator. */ + if (!(lhs->flags & PASTE_LEFT)) + abort (); + + if (context->tokens_kind == TOKENS_KIND_EXTENDED) + /* The caller must have called consume_next_token_from_context + right before calling us. That has incremented the pointer to + the current virtual location. So it now points to the location + of the token that comes right after *LHS. We want the + resulting pasted token to have the location of the current + *LHS, though. */ + virt_loc = *(context->c.mc->cur_virt_loc - 1); do { @@ -650,7 +665,18 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs) while (rhs->flags & PASTE_LEFT); /* Put the resulting token in its own context. */ - _cpp_push_token_context (pfile, NULL, lhs, 1); + if (context->tokens_kind == TOKENS_KIND_EXTENDED) + { + source_location *virt_locs = NULL; + _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs); + tokens_buff_add_token (token_buf, virt_locs, lhs, + virt_loc, 0, NULL, 0); + push_extended_tokens_context (pfile, context->c.mc->macro_node, + token_buf, virt_locs, + (const cpp_token **)token_buf->base, 1); + } + else + _cpp_push_token_context (pfile, NULL, lhs, 1); } /* Returns TRUE if the number of arguments ARGC supplied in an