From patchwork Tue Jun 4 12:29:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 248567 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 1D35B2C00A2 for ; Tue, 4 Jun 2013 22:29:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=QgZzGJbpgyivJ3rmSq0l2CqWwjNGUNssQJQwkQdJaMHX6pRnJDEeq 81U9zIa4Q0iVmuxHw1SvB/qfF+7IweE1WpbnhQPaGUe6YZXmcLPADoPApqbwqqOX 7b8u/MGjOwcAYqsbf0oQa9AnYRLw1p+7y/YNrF5oNzz/7wXx9Yg/IA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=quXiSzAJkfFJnnmVdNN8s8mPuLs=; b=rxSWn0LR33VpuY1XnsrfI80BwV0r kJTtBrkQj2tXmmUVsRsBm6fEHMhLdTstRf0emUKyv5RBkHVS2P+1MU+AtxihFoQx W5X5OBcFt1xqAubd/dQh901HUSwLh8IpeTbFc2j9+H3ujNg7ZTxqQQJcmnB/WfSA zN5UX5TBvqn/aBg= Received: (qmail 11537 invoked by alias); 4 Jun 2013 12:29:23 -0000 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 Received: (qmail 11503 invoked by uid 89); 4 Jun 2013 12:29:19 -0000 X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, COMPENSATION autolearn=no version=3.3.1 Received: from seketeli.net (HELO ms.seketeli.net) (91.121.166.71) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 04 Jun 2013 12:29:17 +0000 Received: from localhost (torimasen.com [82.237.12.13]) by ms.seketeli.net (Postfix) with ESMTP id 81D63EA04D; Tue, 4 Jun 2013 14:59:13 +0200 (CEST) Received: by localhost (Postfix, from userid 1000) id D380916438D; Tue, 4 Jun 2013 14:29:14 +0200 (CEST) From: Dodji Seketeli To: Dehao Chen Cc: GCC Patches , Richard Biener , Tom Tromey Subject: Re: [PATCH, libcpp] Do not decrease highest_location if the included file has be included twice. References: <8761xvowvq.fsf@seketeli.org> X-URL: http://www.seketeli.net/~dodji Date: Tue, 04 Jun 2013 14:29:14 +0200 In-Reply-To: (Dehao Chen's message of "Mon, 3 Jun 2013 16:24:53 -0700") Message-ID: <87k3magiud.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) MIME-Version: 1.0 Dehao Chen a écrit: >> So, I'd say that in this hunk of your patch: >> >>> @@ -1002,7 +1002,8 @@ _cpp_stack_include (cpp_reader *pfile, const char >>> linemap_add is not called) or we were included from the >>> command-line. */ >>> if (file->pchname == NULL && file->err_no == 0 >>> - && type != IT_CMDLINE && type != IT_DEFAULT) >>> + && type != IT_CMDLINE && type != IT_DEFAULT >>> + && !(file->cmacro && file->cmacro->type == NT_MACRO)) >> >> Maybe you should test: >> >> && should_stack_file (pfile, file, type == IT_IMPORT) >> >> rather than testing the last conjunction you added? This is because >> there are many conditions that could make the header to not be loaded, >> besides the one you are testing. Would this work in your environment? > > I tried to apply this change, but it failed several PCH related > regression tests. Of course ... sigh. So, should_stack_file apparently sets some state to (among other things) flag files loaded via #import as 'imported'. And using it here prevents the file to be really imported later. That kind of things. And some the pch related failures involve using #import. So my idea was a bad one. So how about this patch then? It passes bootstrap on x86_64-unknown-linux-gnu for all,ada,obj{c,c++} here but then I don't know if it fixes the issue on you giant input file. If it does and if the maintainers think it can go in, I'll let you handle the ChangeLog and commit. Cheers. diff --git a/libcpp/files.c b/libcpp/files.c index 5c5a0b9..be80be3 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, { struct cpp_dir *dir; _cpp_file *file; + bool stacked; dir = search_path_head (pfile, fname, angle_brackets, type); if (!dir) @@ -993,19 +994,26 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, if (type == IT_DEFAULT && file == NULL) return false; - /* Compensate for the increment in linemap_add that occurs in - _cpp_stack_file. In the case of a normal #include, we're - currently at the start of the line *following* the #include. A - separate source_location for this location makes no sense (until - we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION. - This does not apply if we found a PCH file (in which case - linemap_add is not called) or we were included from the - command-line. */ + /* Compensate for the increment in linemap_add that occurs if + _cpp_stack_file actually stacks the file. In the case of a + normal #include, we're currently at the start of the line + *following* the #include. A separate source_location for this + location makes no sense (until we do the LC_LEAVE), and + complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we + found a PCH file (in which case linemap_add is not called) or we + were included from the command-line. */ if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE && type != IT_DEFAULT) pfile->line_table->highest_location--; - return _cpp_stack_file (pfile, file, type == IT_IMPORT); + stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT); + + if (!stacked) + /* _cpp_stack_file didn't stack the file, so let's rollback the + compensation dance we performed above. */ + pfile->line_table->highest_location++; + + return stacked; } /* Could not open FILE. The complication is dependency output. */