From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106790 invoked by alias); 1 Nov 2018 15:58:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 106670 invoked by uid 89); 1 Nov 2018 15:58:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:linemap, cpp_reader, line_table, pfile X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Nov 2018 15:58:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mathworks.com; s=mimecast20180117; t=1541087888; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pjez8RTg9zvjM9VG6TAE7lNJaMzQKgB3xDxACOAUlwg=; b=ZJWAoEi9L8NXadISKoaiytTEJ8NPBT38AFxPvwPrP0v0/0ZXMU/8aIVscyUkIo1/eIlS4eky7sM+d71Rzs863pAJNqWWCbTJdLxMsjRmtTv3LLym+NASbeZc7Y9iD1JkpCjbQpPNZFgBNVz2bKHIdED36pKTeXsxWcmeFvaF2KI= Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-sn1nam04lp0084.outbound.protection.outlook.com [216.32.180.84]) (Using TLS) by dkim.mimecast.com with ESMTP id us-mta-77-_oSfJNzlMgemISJNhL9Mwg-1; Thu, 01 Nov 2018 11:58:07 -0400 Received: from SN4PR0501CA0008.namprd05.prod.outlook.com (2603:10b6:803:40::21) by CY4PR05MB3573.namprd05.prod.outlook.com (2603:10b6:910:50::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.14; Thu, 1 Nov 2018 15:58:03 +0000 Received: from DM3NAM05FT031.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::208) by SN4PR0501CA0008.outlook.office365.com (2603:10b6:803:40::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1294.11 via Frontend Transport; Thu, 1 Nov 2018 15:58:03 +0000 Received: from exedge.mathworks.com (144.212.100.42) by DM3NAM05FT031.mail.protection.outlook.com (10.152.98.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1318.5 via Frontend Transport; Thu, 1 Nov 2018 15:58:02 +0000 Received: from ex16-01-ah.mathworks.com (172.31.80.219) by ex16edge-00-ah.mathworks.com (172.31.187.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Thu, 1 Nov 2018 11:56:59 -0400 Received: from ex16-00-ah.mathworks.com (172.31.39.22) by ex16-01-ah.mathworks.com (172.31.80.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3; Thu, 1 Nov 2018 11:57:42 -0400 Received: from mail-vif.mathworks.com (144.212.95.101) by ex16-00-ah.mathworks.com (172.31.39.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1466.3 via Frontend Transport; Thu, 1 Nov 2018 11:57:42 -0400 Received: from mgulick-deb9-64.dhcp.mathworks.com (mgulick-deb9-64.dhcp.mathworks.com [172.21.82.68]) by mail-vif.mathworks.com (8.14.7/8.14.7) with ESMTP id wA1Fvgop015419; Thu, 1 Nov 2018 11:57:42 -0400 Received: (from mgulick@localhost) by mgulick-deb9-64.dhcp.mathworks.com (8.15.2/8.15.2/Submit) id wA1FvgKU019291; Thu, 1 Nov 2018 11:57:42 -0400 From: Mike Gulick To: CC: David Malcolm , Mike Gulick Subject: [PATCH v3 1/3] PR preprocessor/83173: Additional check before decrementing highest_location Date: Thu, 01 Nov 2018 15:58:00 -0000 Message-ID: <20181101155607.11388-2-mgulick@mathworks.com> In-Reply-To: <20181101155607.11388-1-mgulick@mathworks.com> References: <7d281f10-a4e0-d81e-c405-d77ceda86f5b@mathworks.com> <20181101155607.11388-1-mgulick@mathworks.com> MIME-Version: 1.0 Return-Path: Mike.Gulick@mathworks.com Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-11/txt/msg00026.txt.bz2 2018-10-31 Mike Gulick PR preprocessor/83173 * libcpp/files.c (_cpp_stack_include): Check if line_table->highest_location is past current line before decrementing. --- libcpp/files.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libcpp/files.c b/libcpp/files.c index 08b7c647c91..c0165fe64e4 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1012,6 +1012,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fn= ame, int angle_brackets, struct cpp_dir *dir; _cpp_file *file; bool stacked; + bool decremented =3D false; =20 /* For -include command-line flags we have type =3D=3D IT_CMDLINE. When the first -include file is processed we have the case, where @@ -1035,20 +1036,33 @@ _cpp_stack_include (cpp_reader *pfile, const char *= fname, int angle_brackets, return false; =20 /* 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. */ + _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. In the case that the #include is the last + line in the file, highest_location still points to the current + line, not the start of the next line, so we do not decrement in + this case. See plugin/location-overflow-test-pr83173.h for an + example. */ if (file->pchname =3D=3D NULL && file->err_no =3D=3D 0 && type !=3D IT_CMDLINE && type !=3D IT_DEFAULT) - pfile->line_table->highest_location--; + { + int highest_line =3D linemap_get_expansion_line (pfile->line_table, + pfile->line_table->highest_location); + int source_line =3D linemap_get_expansion_line (pfile->line_table, l= oc); + if (highest_line > source_line) + { + pfile->line_table->highest_location--; + decremented =3D true; + } + } =20 stacked =3D _cpp_stack_file (pfile, file, type =3D=3D IT_IMPORT, loc); =20 - if (!stacked) + if (decremented && !stacked) /* _cpp_stack_file didn't stack the file, so let's rollback the compensation dance we performed above. */ pfile->line_table->highest_location++; --=20 2.19.1