From patchwork Tue Aug 16 20:38:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gab Charette X-Patchwork-Id: 110223 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 BABEEB6F7F for ; Wed, 17 Aug 2011 06:39:08 +1000 (EST) Received: (qmail 18959 invoked by alias); 16 Aug 2011 20:39:06 -0000 Received: (qmail 18943 invoked by uid 22791); 16 Aug 2011 20:39:04 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Aug 2011 20:38:50 +0000 Received: from hpaq14.eem.corp.google.com (hpaq14.eem.corp.google.com [172.25.149.14]) by smtp-out.google.com with ESMTP id p7GKcmn1007983; Tue, 16 Aug 2011 13:38:49 -0700 Received: from gchare.mtv.corp.google.com (gchare.mtv.corp.google.com [172.18.111.122]) by hpaq14.eem.corp.google.com with ESMTP id p7GKckKh023497; Tue, 16 Aug 2011 13:38:47 -0700 Received: by gchare.mtv.corp.google.com (Postfix, from userid 138564) id 35FB11C1050; Tue, 16 Aug 2011 13:38:46 -0700 (PDT) To: reply@codereview.appspotmail.com, crowl@google.com, dnovillo@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Force token location for replayed macro definitions (issue4905050) Message-Id: <20110816203846.35FB11C1050@gchare.mtv.corp.google.com> Date: Tue, 16 Aug 2011 13:38:46 -0700 (PDT) From: gchare@google.com (Gabriel Charette) X-System-Of-Record: true X-IsSubscribed: yes 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 follows issue4907044. Replayed definitions were given new source locations in the lexer. This would shift all of the locations assigned later and since this replay is absent in the non-pph, we get different source_locations for the tokens following the replay in pph. This improves the quality of the pph line_table (closer and closer to the non-pph line_table, but not perfect yet). Tested with bootstrap and pph regression testing. Gab 2011-08-16 Gabriel Charette gcc/cp/ChangeLog.pph * pph-streamer-in.c (pph_read_file_1): Set location of replayed tokens to column 0 of the line the pph file was included on. libcpp/ChangeLog.pph * include/symtab.h (line-map.h): Add dependency. * symtab.c (cpp_lt_replay): Add LOC parameter and force locations of tokens replayed to *LOC if non-null. --- This patch is available for review at http://codereview.appspot.com/4905050 diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c index f87e6a5..8d25de8 100644 --- a/gcc/cp/pph-streamer-in.c +++ b/gcc/cp/pph-streamer-in.c @@ -1485,6 +1485,7 @@ pph_read_file_1 (pph_stream *stream) tree t, file_keyed_classes, file_static_aggregates; unsigned i; VEC(tree,gc) *file_unemitted_tinfo_decls; + source_location cpp_token_replay_loc; if (flag_pph_debug >= 1) fprintf (pph_logfile, "PPH: Reading %s\n", stream->name); @@ -1502,8 +1503,13 @@ pph_read_file_1 (pph_stream *stream) report_validation_error (stream->name, bad_use->ident_str, cur_def, bad_use->before_str, bad_use->after_str); - /* Re-instantiate all the pre-processor symbols defined by STREAM. */ - cpp_lt_replay (parse_in, &idents_used); + /* Re-instantiate all the pre-processor symbols defined by STREAM. Force + their source_location to column 0 of the line the include occured on, + this avoids shifting all of the line_table's location as we would by adding + locations which wouldn't be there in the non-pph compile; thus working + towards an identical line_table in pph and non-pph. */ + cpp_token_replay_loc = linemap_position_for_column (line_table, 0); + cpp_lt_replay (parse_in, &idents_used, &cpp_token_replay_loc); /* Read in STREAM's line table and merge it in the current line table. */ pph_in_and_merge_line_table (stream, line_table); diff --git a/libcpp/include/symtab.h b/libcpp/include/symtab.h index b5d6492..c39fa26 100644 --- a/libcpp/include/symtab.h +++ b/libcpp/include/symtab.h @@ -20,6 +20,7 @@ along with this program; see the file COPYING3. If not see #define LIBCPP_SYMTAB_H #include "obstack.h" +#include "line-map.h" #ifndef GTY #define GTY(x) /* nothing */ @@ -167,7 +168,8 @@ cpp_lt_verify (struct cpp_reader *reader, cpp_idents_used* identifiers, /* Replay the macro definitions captured by the table of IDENTIFIERS into the READER state. */ void -cpp_lt_replay (struct cpp_reader *reader, cpp_idents_used* identifiers); +cpp_lt_replay (struct cpp_reader *reader, cpp_idents_used* identifiers, + source_location *loc); /* Destroy IDENTIFIERS captured. */ void diff --git a/libcpp/symtab.c b/libcpp/symtab.c index aad7277..b2e72f1 100644 --- a/libcpp/symtab.c +++ b/libcpp/symtab.c @@ -818,10 +818,12 @@ cpp_lt_define_syntax (char *needed, const char *ident, const char *given) } /* Replay the macro definitions captured by the table of IDENTIFIERS - into the READER state. */ + into the READER state. If LOC is non-null, assign *LOC as the + source_location to all macro definitions replayed. */ void -cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers) +cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers, + source_location *loc) { unsigned int i; unsigned int num_entries = identifiers->num_entries; @@ -832,6 +834,9 @@ cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers) /* Prevent the lexer from invalidating the tokens we've read so far. */ reader->keep_tokens++; + if (loc) + cpp_force_token_locations (reader, loc); + for (i = 0; i < num_entries; ++i) { cpp_ident_use *entry = entries + i; @@ -865,6 +870,9 @@ cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers) reader->keep_tokens--; + if (loc) + cpp_stop_forcing_token_locations (reader); + free (buffer); }