From patchwork Tue Jun 4 17:02:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 248767 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 9233D2C009D for ; Wed, 5 Jun 2013 03:02:48 +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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=qmWGSIzCCwYpMLDjes MWCyIbkLjb27xYJEsBXnXJmKfbwKZChGpr+JfLCr1pdu0Elbmt7t9zaI9YwQ3gpb yAPGatXDHpIAtRIfXw9yWgTjZnJ3oi2ypxfofnfdMUiswDiVJsVbLQoYox0TMf/S h7IRaxXy+tynXStb38fEAr3/c= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=Pb9TqjG6SJlUGZwUaXa8/c6a 1As=; b=CXJ0bLZFk81zxPZZUZ+LjAUbua10DCK6aXGcB/iOkbplIa3dzfuSY/s9 C6bwmYlKXwOQuioL+0mDWMa2u/hinkSRfut7s0+et8lbtvZoPpbzE7TiByqT/KtO GLu0Ww0ACePCEK/pDnS0dJfX7fSID/AwKhdDTuj99bScnUqXfeY= Received: (qmail 26579 invoked by alias); 4 Jun 2013 17:02:42 -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 26561 invoked by uid 89); 4 Jun 2013 17:02:42 -0000 X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_05, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.1 Received: from mail-ea0-f170.google.com (HELO mail-ea0-f170.google.com) (209.85.215.170) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 04 Jun 2013 17:02:41 +0000 Received: by mail-ea0-f170.google.com with SMTP id h10so396101eaj.29 for ; Tue, 04 Jun 2013 10:02:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=pO1Hl2cM/tcdD4s8g4Hfq7Zciu+KkV6WE6yEb0aiEvs=; b=QHH422OhMZIlGl8aNEINo0sAvhQepnA3WqF9rl/PSk4Xe9ANbGtzq6XpwsjVoSKN7U T4tVpj5c5fa8uuN5Yr2dZmoLcfKq+PAxsh4W1uEJaynPPdz4nxFiKHD14GUmo+4jHv1P DTU0rUQuy7I05J0rJZWBq+gvfXX8b1t0vjbPrOFwrHpmQzEm46FSr5ABNGiRPCkEYTF1 6qqbpsO+gbIZuA1YBNkZsyxiP/NzTefKQ99A8N/miir2waois42C4a5d6TI5HnuMywls LqVryHQ5ddFsLuV8p1aF6vWwge4npmWN3GAi5tR+ck+vzLwX6dpkAg5XfICfJS+ht6uV W5EQ== MIME-Version: 1.0 X-Received: by 10.14.209.5 with SMTP id r5mr27213352eeo.112.1370365359437; Tue, 04 Jun 2013 10:02:39 -0700 (PDT) Received: by 10.14.220.9 with HTTP; Tue, 4 Jun 2013 10:02:39 -0700 (PDT) In-Reply-To: <87k3magiud.fsf@seketeli.org> References: <8761xvowvq.fsf@seketeli.org> <87k3magiud.fsf@seketeli.org> Date: Tue, 4 Jun 2013 10:02:39 -0700 Message-ID: Subject: Re: [PATCH, libcpp] Do not decrease highest_location if the included file has be included twice. From: Dehao Chen To: Dodji Seketeli Cc: GCC Patches , Richard Biener , Tom Tromey X-Gm-Message-State: ALoCoQk/acRzTA3S9vCNGJ2gyvg/Vi3wDNh7iKMmntu5OrVMOAehdJ1hPn37Jw0O4yOe4VJGt5OJFyWVnKQwDzMKR3VT50042htg0ZaR1mqjAdUU8enQVUygtKOseFZ0szQD8d4gr18+SNVTnJwv/kDP9qXSym8elvnqe0DZ7HJGlfLGJ5Q2gd8ztEdUKp6aFwUmO9jMoudR Hi, Dodji, Thanks for helping update the patch. The new patch passed all regression test and can fix the problem in my huge source file. I added ChangeLog entry to the patch. Could any libcpp maintainers help check if it is ok for trunk? Thanks, Dehao libcpp/ChangeLog: 2013-06-04 Dehao Chen * files.c (_cpp_stack_include): Fix the highest_location when header file is guarded by #ifndef and is included twice. Index: libcpp/files.c =================================================================== --- libcpp/files.c (revision 199570) +++ libcpp/files.c (working copy) @@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char { 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 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. */