From patchwork Thu Mar 24 15:20:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 601637 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qW9BM1HPDz9rxl for ; Fri, 25 Mar 2016 02:21:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=BjsKCsa0; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=UzkfEBnajXvMO+DQS sXPO5+0dH+fnA3xstpSTD+wGIt5nK0FrvqdLvSoYgiAa6ypZXBtzBgRWigQGrs+Y fTTPPkNo4h/jqbvv1ZoseqJhbIR6ii/395Bj8a697CTUfn83x8E8FJ8Rai5o8G4h zqF6yGUEwlrorPMHrrFaa0jqpo= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=xeEY9KHrUKCi0kExKznWAl4 HTZ8=; b=BjsKCsa0FjKc/m7hxJ+r18LPK9JtlXbUUR8/fptUPrqTLlpRUXzI3fw FMYFbexK/IpAQ5t8Ow/ObsJw+ANMg/w1+/sROAUIU2Scx3er7RKzQS/7HHgsYv84 O+rP77VARvUdCVM+e3a+qAeifDVQM5KYzUNuNQcxEKh9YZAiXAe0= Received: (qmail 2975 invoked by alias); 24 Mar 2016 15:21:06 -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 2959 invoked by uid 89); 24 Mar 2016 15:21:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=Depending X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 24 Mar 2016 15:21:03 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id DB7EF7F6D0; Thu, 24 Mar 2016 15:21:01 +0000 (UTC) Received: from localhost.localdomain (vpn1-4-159.ams2.redhat.com [10.36.4.159]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2OFKxWc009395; Thu, 24 Mar 2016 11:21:00 -0400 Subject: Re: Fix 69650, bogus line numbers from libcpp To: Richard Biener References: <56E12FFF.6050800@t-online.de> <56E132FC.2030404@redhat.com> <1457734166.5425.43.camel@redhat.com> <56E6BAB1.6030804@redhat.com> <1458591323.9902.81.camel@redhat.com> <56F07CA0.5040607@redhat.com> <56F296D5.8050204@redhat.com> Cc: David Malcolm , GCC Patches From: Bernd Schmidt Message-ID: <56F405DB.1060600@redhat.com> Date: Thu, 24 Mar 2016 16:20:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 03/23/2016 03:21 PM, Richard Biener wrote: > On Wed, Mar 23, 2016 at 2:15 PM, Bernd Schmidt wrote: >> On 03/23/2016 01:41 PM, Richard Biener wrote: >>> >>> Btw, the issue in the PR is also fixed with a simple >>> >>> Index: libcpp/line-map.c >>> =================================================================== >>> --- libcpp/line-map.c (revision 234415) >>> +++ libcpp/line-map.c (working copy) >>> @@ -543,7 +543,7 @@ linemap_add (struct line_maps *set, enum >>> to_file); >>> >>> /* A TO_FILE of NULL is special - we use the natural values. */ >>> - if (error || to_file == NULL) >>> + if (to_file == NULL) >>> { >>> to_file = ORDINARY_MAP_FILE_NAME (from); >>> to_line = SOURCE_LINE (from, from[1].start_location); >> >> >> I looked at that, but that made it hard to add the testcase as the line >> numbers no longer match the dg-error directives. By moving this code we can >> ignore the erroneous #line directive, and for this one testcase at least, >> that makes the line numbers (and caret diagnostics etc.) come out right. > > After some more digging and looking at your patch I'd approve that if it would > emit a warning rather than an error - so can you please adjust it? Like this? No one has yet approved any better wording for the message, so given that you said "it's not a regression" I've left it, but I would now prefer "linemarker ignored due to incorrect nesting". Bernd PR lto/69650 * directives.c (do_linemarker): Test for file left but not entered here. * line-map.c (linemap_add): Not here. PR lto/69650 * gcc.dg/pr69650.c: New test. Index: gcc/testsuite/gcc.dg/pr69650.c =================================================================== --- gcc/testsuite/gcc.dg/pr69650.c (revision 0) +++ gcc/testsuite/gcc.dg/pr69650.c (working copy) @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +# 9 "somefile" 2 /* { dg-warning "left but not entered" } */ +not_a_type a; /* { dg-error "unknown type" } */ Index: libcpp/directives.c =================================================================== --- libcpp/directives.c (revision 234341) +++ libcpp/directives.c (working copy) @@ -1046,6 +1046,19 @@ skip_rest_of_line (pfile); + if (reason == LC_LEAVE) + { + const line_map_ordinary *from; + if (MAIN_FILE_P (map) + || (new_file + && (from = INCLUDED_FROM (pfile->line_table, map)) != NULL + && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0)) + { + cpp_warning (pfile, CPP_W_NONE, + "file \"%s\" left but not entered", new_file); + return; + } + } /* Compensate for the increment in linemap_add that occurs in _cpp_do_file_change. We're currently at the start of the line *following* the #line directive. A separate source_location for this Index: libcpp/line-map.c =================================================================== --- libcpp/line-map.c (revision 234341) +++ libcpp/line-map.c (working copy) @@ -512,43 +512,23 @@ "included", this variable points the map in use right before the #include "included", inside the same "includer" file. */ line_map_ordinary *from; - bool error; - if (MAIN_FILE_P (map - 1)) - { - /* So this _should_ mean we are leaving the main file -- - effectively ending the compilation unit. But to_file not - being NULL means the caller thinks we are leaving to - another file. This is an erroneous behaviour but we'll - try to recover from it. Let's pretend we are not leaving - the main file. */ - error = true; - reason = LC_RENAME; - from = map - 1; - } - else - { - /* (MAP - 1) points to the map we are leaving. The - map from which (MAP - 1) got included should be the map - that comes right before MAP in the same file. */ - from = INCLUDED_FROM (set, map - 1); - error = to_file && filename_cmp (ORDINARY_MAP_FILE_NAME (from), - to_file); - } + linemap_assert (!MAIN_FILE_P (map - 1)); + /* (MAP - 1) points to the map we are leaving. The + map from which (MAP - 1) got included should be the map + that comes right before MAP in the same file. */ + from = INCLUDED_FROM (set, map - 1); - /* Depending upon whether we are handling preprocessed input or - not, this can be a user error or an ICE. */ - if (error) - fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n", - to_file); - /* A TO_FILE of NULL is special - we use the natural values. */ - if (error || to_file == NULL) + if (to_file == NULL) { to_file = ORDINARY_MAP_FILE_NAME (from); to_line = SOURCE_LINE (from, from[1].start_location); sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from); } + else + linemap_assert (filename_cmp (ORDINARY_MAP_FILE_NAME (from), + to_file) == 0); } map->sysp = sysp;