From patchwork Thu Dec 4 23:36:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 417963 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 A28BA1400D2 for ; Fri, 5 Dec 2014 10:37:21 +1100 (AEDT) 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:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; q=dns; s= default; b=v4blofmx/U2o1Smid5fBriFJR5rDuTkn/JRethnCvOGEf0oLlhNox T+4Bff4+m96wWE+yHxHjfK7LyAVtiBqWQ0Kxjzj3ntgEFE0Xv47bMEySv8hYOIkG OxaljzFQLos93vQFOK19dFFR5e/0s1hYCvA4/WFgqHJ2CtWY6ctgJk= 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:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; s= default; bh=xR+Hpl/IjVA/bmvTYz48uXTL2Qo=; b=FbfFo82wOuqJuqvWaHdu IObQ6r02aosEv65Jc+kAz1KINbCNDfutKQhBaDixaXnDLJ/sYCX8xtWlyy8J6qtS H4TKFN4giKinAlKofj5UsZfww9GuNuxJhuBWNwcasQq519RLN2hp21PIRoJJCFVc nDqU1ZBenrtWojZnGVhfPjg= Received: (qmail 12775 invoked by alias); 4 Dec 2014 23:37:14 -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 12755 invoked by uid 89); 4 Dec 2014 23:37:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wg0-f51.google.com Received: from mail-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 04 Dec 2014 23:37:12 +0000 Received: by mail-wg0-f51.google.com with SMTP id k14so23711483wgh.24 for ; Thu, 04 Dec 2014 15:37:09 -0800 (PST) X-Received: by 10.180.73.7 with SMTP id h7mr767076wiv.83.1417736229642; Thu, 04 Dec 2014 15:37:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.217.141.72 with HTTP; Thu, 4 Dec 2014 15:36:29 -0800 (PST) In-Reply-To: <20141204102151.GA23875@physik.fu-berlin.de> References: <20141204102151.GA23875@physik.fu-berlin.de> From: =?ISO-8859-1?Q?Manuel_L=F3pez=2DIb=E1=F1ez?= Date: Fri, 5 Dec 2014 00:36:29 +0100 Message-ID: Subject: Re: [PATCH fortran/linemap] Add enough column hint to fit any possible offset To: Tobias Burnus Cc: Gcc Patch List , "fortran@gcc.gnu.org List" , Dodji Seketeli , Tobias Burnus On 4 December 2014 at 11:21, Tobias Burnus wrote: > Manuel López-Ibáñez wrote: >> It is still not clear to me if line_len is the length of the line read >> or not, is it? If not, is there any way to actually get the length of >> the line? > > Looking at the code in load_line, the line_len in > > int trunc = load_line (input, &line, &line_len, NULL); > > is the size of the buffer. That's not too bad but usually to large. However, > the actual line length is determined one line later: > > len = gfc_wide_strlen (line); > > which does a strlen on gfc_char_t which is uint32_t to accomodate unicode > characters. > > > Hence, I think > > b->location > - = linemap_line_start (line_table, current_file->line++, 120); > + = linemap_line_start (line_table, current_file->line++, line_len); > > should use "len" instead of "line_len". Great! That works. It also seems to keep working when I convert all gfc_error to the common diagnostics (but that still needs a bit more work). Dodji, I noticed that there is yet another situation where the offset computation may fail. If we are in the last map, but no columns have been allocated, any offset will trigger an assert within linemap_lookup because the loc+offset > set->highest_location. This is a bit unfortunate, since being in the last map means that we could have extended the map or created a new one simply by calling linemap_position_for_column instead of linemap_position_for_line_and_column. Do you think that may break something else? For now I just added a linemap_assert_fails to fail gracefully if this ever happens. The patch I committed is below. Cheers, Manuel. Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 218406) +++ gcc/testsuite/ChangeLog (revision 218407) @@ -1,3 +1,7 @@ +2014-12-05 Manuel López-Ibáñez + + * gfortran.dg/line_length_5.f90: New test. + 2014-12-04 Sriraman Tallam H.J. Lu Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (revision 218406) +++ gcc/fortran/ChangeLog (revision 218407) @@ -1,3 +1,10 @@ +2014-12-05 Manuel López-Ibáñez + + * scanner.c (gfc_next_char_literal): Use gfc_warning_now. + (load_file): Use the line length as the column hint for + linemap_line_start. Reserve a location for the highest column of + the line. + 2014-12-03 Manuel López-Ibáñez PR fortran/44054 Index: gcc/fortran/scanner.c =================================================================== --- gcc/fortran/scanner.c (revision 218406) +++ gcc/fortran/scanner.c (revision 218407) @@ -1056,7 +1056,8 @@ gfc_current_locus.lb->truncated = 0; gfc_current_locus.nextc = gfc_current_locus.lb->line + maxlen; - gfc_warning_now_1 ("Line truncated at %L", &gfc_current_locus); + gfc_warning_now (OPT_Wline_truncation, + "Line truncated at %L", &gfc_current_locus); gfc_current_locus.nextc = current_nextc; } @@ -1195,7 +1196,8 @@ && gfc_current_locus.lb->truncated) { gfc_current_locus.lb->truncated = 0; - gfc_warning_now_1 ("Line truncated at %L", &gfc_current_locus); + gfc_warning_now (OPT_Wline_truncation, + "Line truncated at %L", &gfc_current_locus); } prev_openmp_flag = openmp_flag; @@ -2044,7 +2046,13 @@ + (len + 1) * sizeof (gfc_char_t)); b->location - = linemap_line_start (line_table, current_file->line++, 120); + = linemap_line_start (line_table, current_file->line++, len); + /* ??? We add the location for the maximum column possible here, + because otherwise if the next call creates a new line-map, it + will not reserve space for any offset. */ + if (len > 0) + linemap_position_for_column (line_table, len); + b->file = current_file; b->truncated = trunc; wide_strcpy (b->line, line); Index: libcpp/line-map.c =================================================================== --- libcpp/line-map.c (revision 218406) +++ libcpp/line-map.c (revision 218407) @@ -678,7 +678,8 @@ linemap_position_for_line_and_column (map, SOURCE_LINE (map, loc), offset); - if (linemap_assert_fails (map == linemap_lookup (set, r))) + if (linemap_assert_fails (r <= set->highest_location) + || linemap_assert_fails (map == linemap_lookup (set, r))) return loc; return r; Index: libcpp/ChangeLog =================================================================== --- libcpp/ChangeLog (revision 218406) +++ libcpp/ChangeLog (revision 218407) @@ -1,3 +1,8 @@ +2014-12-05 Manuel López-Ibáñez + + * line-map.c (linemap_position_for_loc_and_offset): Add new + linemap_assert_fails. + 2014-12-02 Manuel López-Ibáñez * include/line-map.h (linemap_assert_fails): Declare.