From patchwork Thu Dec 8 21:22:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 130230 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 0C49E1007D1 for ; Fri, 9 Dec 2011 08:22:43 +1100 (EST) Received: (qmail 28747 invoked by alias); 8 Dec 2011 21:22:40 -0000 Received: (qmail 28732 invoked by uid 22791); 8 Dec 2011 21:22:38 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-gx0-f201.google.com (HELO mail-gx0-f201.google.com) (209.85.161.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Dec 2011 21:22:22 +0000 Received: by ggnv5 with SMTP id v5so260613ggn.2 for ; Thu, 08 Dec 2011 13:22:21 -0800 (PST) Received: by 10.101.197.23 with SMTP id z23mr1408621anp.48.1323379341899; Thu, 08 Dec 2011 13:22:21 -0800 (PST) Received: by 10.101.197.23 with SMTP id z23mr1408607anp.48.1323379341775; Thu, 08 Dec 2011 13:22:21 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id u11si2829025anh.3.2011.12.08.13.22.21 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 08 Dec 2011 13:22:21 -0800 (PST) Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by wpzn4.hot.corp.google.com (Postfix) with ESMTPS id B61F11E004D; Thu, 8 Dec 2011 13:22:21 -0800 (PST) Received: from tobiano.tor.corp.google.com (tobiano.tor.corp.google.com [172.29.41.6]) by wpaz5.hot.corp.google.com with ESMTP id pB8LMKB9019521; Thu, 8 Dec 2011 13:22:20 -0800 Received: by tobiano.tor.corp.google.com (Postfix, from userid 54752) id 16342AE1DB; Thu, 8 Dec 2011 16:22:19 -0500 (EST) To: reply@codereview.appspotmail.com, crowl@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Fix references to external PPH files (issue5476043) Message-Id: <20111208212220.16342AE1DB@tobiano.tor.corp.google.com> Date: Thu, 8 Dec 2011 16:22:19 -0500 (EST) From: dnovillo@google.com (Diego Novillo) 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 fixes a bug in the creation of external references to PPH images. We save references to external PPH files when we save the line table for the parent header. Sometimes we were not saving a proper reference because the path names of the header as found in the line map could not be matched with the external PPH file. This fixes the problem by encoding the path name of the original header file into each PPH file. This way, we do not have to play guessing games when saving the line table. We are still dependent on the path names of the original headers to be in the same location that the PPH was generated from. If a header moves to a different location, then we won't be able to match it to a PPH image. The final solution will involve being cognizant of the path scheme used by libcpp, but this will serve for the time being. Tested on x86_64. Committed. Diego. * pph-streamer.h (struct pph_stream): Add field HEADER_NAME. * pph-in.c (pph_in_line_table_and_includes): Read it. * pph-out.c (pph_init_write): Initialize it from input_filename. (pph_filename_eq_ignoring_path): Remove. (pph_out_line_table_and_includes): Write STREAM->HEADER_NAME. Compare the file name in LM against STREAM->HEADER_NAME to decide whether to write a reference to an external PPH. --- This patch is available for review at http://codereview.appspot.com/5476043 diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c index 52a56aa..323516d 100644 --- a/gcc/cp/pph-in.c +++ b/gcc/cp/pph-in.c @@ -355,6 +355,10 @@ pph_in_line_table_and_includes (pph_stream *stream) used_before = LINEMAPS_ORDINARY_USED (line_table); first = true; + /* Read the path name of the original text header file that was + used to generate STREAM. */ + stream->header_name = pph_in_string (stream); + /* All line map entries that have -1 as the includer, will now be relocated to the current last line map entry in the line table. */ top_includer_ix = used_before - 1; diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c index e970f86..01c364a 100644 --- a/gcc/cp/pph-out.c +++ b/gcc/cp/pph-out.c @@ -65,6 +65,10 @@ pph_init_write (pph_stream *stream) /* Associate STREAM with stream->encoder.w.ob so we can recover it from the streamer hooks. */ stream->encoder.w.ob->sdata = (void *) stream; + + /* Since we are about to generate STREAM, its header name is the + name of the header file that we are currently parsing. */ + stream->header_name = xstrdup (input_filename); } @@ -280,45 +284,6 @@ pph_out_include (pph_stream *stream, pph_stream *include, } -/* Compare filenames of a header and it's potentially corresponding pph file, - stripping the path passed in and the extension. Returns true if HEADER_PATH - and PPH_PATH end with the same filename. We expect HEADER_PATH to end in .h - and PPH_PATH to end in .pph. - - FIXME pph: We should not need to do this if we handled include paths - correctly, but for now the linemap holds full paths and the stream's includes - list only holds the include name. Also, the stream's includes hold pph - filenames where as the line_table as header filenames. */ - -static bool -pph_filename_eq_ignoring_path (const char *header_path, const char *pph_path) -{ - const char *header_name = lbasename (header_path); - const char *pph_name = lbasename (pph_path); - - const char *header_ext = strchr (header_name, '.'); - const char *pph_ext = strchr (pph_name, '.'); - - unsigned int name_length; - - if (header_ext != NULL) - { - name_length = header_ext - header_name; - gcc_assert (strcmp (header_ext, ".h") == 0); - } - else - /* Some headers do not have a .h suffix, but will still - have a .pph suffix after being pph'ed. */ - name_length = strlen (header_name); - - gcc_assert (strcmp (pph_ext, ".pph") == 0); - - /* Compare the filenames without their extension. */ - return pph_ext - pph_name == name_length - && strncmp (header_name, pph_name, name_length) == 0; -} - - /* Return the *NEXT_INCLUDE_IX'th pph_stream in STREAM's list of includes. Returns NULL if we have read all includes. Increments *NEXT_INCLUDE_IX when sucessful. */ @@ -351,6 +316,10 @@ pph_out_line_table_and_includes (pph_stream *stream) /* Any #include should have been fully parsed and exited at this point. */ gcc_assert (line_table->depth == 0); + /* Write the path name of the original text header file that was + used to generate STREAM. */ + pph_out_string (stream, stream->header_name); + current_include = pph_get_next_include (stream, &next_incl_ix); for (ix = PPH_NUM_IGNORED_LINE_TABLE_ENTRIES; @@ -379,8 +348,7 @@ pph_out_line_table_and_includes (pph_stream *stream) reference to it, so the reader can load the included image at this point. */ if (current_include != NULL - && pph_filename_eq_ignoring_path (LINEMAP_FILE (lm), - current_include->name)) + && strcmp (current_include->header_name, LINEMAP_FILE (lm)) == 0) { struct line_map *included_from; diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h index e31b15e..0b8af3d 100644 --- a/gcc/cp/pph-streamer.h +++ b/gcc/cp/pph-streamer.h @@ -164,6 +164,16 @@ struct pph_stream { /* Path name of the PPH file. */ const char *name; + /* Path name of the original text header file. This is the full + path name of the header as found by the pre-processor after + doing include path expansion. Note that this may not necessarily + be an absolute path name. + + We rely on this path name to identify the corresponding PPH name + when deciding whether to load external PPH files in + pph_in_line_table_and_includes. */ + const char *header_name; + /* FILE object associated with it. */ FILE *file;