From patchwork Sun Jul 25 04:01:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 59868 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]) by ozlabs.org (Postfix) with SMTP id 192B1B6EFE for ; Sun, 25 Jul 2010 14:02:12 +1000 (EST) Received: (qmail 2462 invoked by alias); 25 Jul 2010 04:02:08 -0000 Received: (qmail 2325 invoked by uid 22791); 25 Jul 2010 04:02:06 -0000 X-SWARE-Spam-Status: No, hits=3.7 required=5.0 tests=AWL, BAYES_05, BOTNET, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from vms173001pub.verizon.net (HELO vms173001pub.verizon.net) (206.46.173.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 25 Jul 2010 04:02:01 +0000 Received: from [192.168.1.10] ([unknown] [64.234.92.14]) by vms173001.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L6300054HUXKA30@vms173001.mailsrvcs.net>; Sat, 24 Jul 2010 23:01:47 -0500 (CDT) Message-id: <4C4BB728.4070707@verizon.net> Date: Sat, 24 Jul 2010 21:01:44 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5 MIME-version: 1.0 To: gfortran Cc: gcc patches Subject: [patch, fortran] PR42852 -Wall warns about truncated lines when only a continuation character is truncated Content-type: multipart/mixed; boundary=------------010509000302000001090401 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 Hi Folks, This patch provides some enhancement for truncation warnings. Fairly self explanatory. Regression tested on x86-64-linuc-gnu. OK for trunk? Regards, Jerry 2010-07-24 Jerry DeLisle PR fortran/42852 * scanner.c (gfc_next_char_literal): Move check for truncation earlier in the function so that it does not get missed by early exits. (load_line): Add checks for quoted strings and free form comments to disable warnings on comments. Add check for ampersand as first character after truncation and don't warn for this case, but warn if there are subsequent non-whitespace characters. Index: scanner.c =================================================================== --- scanner.c (revision 162507) +++ scanner.c (working copy) @@ -1044,6 +1044,17 @@ restart: goto done; } + /* Check to see if the continuation line was truncated. */ + if (gfc_option.warn_line_truncation && gfc_current_locus.lb != NULL + && gfc_current_locus.lb->truncated) + { + int maxlen = gfc_option.free_line_length; + gfc_current_locus.lb->truncated = 0; + gfc_current_locus.nextc += maxlen; + gfc_warning_now ("Line truncated at %L", &gfc_current_locus); + gfc_current_locus.nextc -= maxlen; + } + if (c != '&') goto done; @@ -1095,17 +1106,6 @@ restart: } } - /* Check to see if the continuation line was truncated. */ - if (gfc_option.warn_line_truncation && gfc_current_locus.lb != NULL - && gfc_current_locus.lb->truncated) - { - int maxlen = gfc_option.free_line_length; - gfc_current_locus.lb->truncated = 0; - gfc_current_locus.nextc += maxlen; - gfc_warning_now ("Line truncated at %L", &gfc_current_locus); - gfc_current_locus.nextc -= maxlen; - } - /* Now find where it continues. First eat any comment lines. */ openmp_cond_flag = skip_free_comments (); @@ -1420,7 +1420,7 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pb static int linenum = 0, current_line = 1; int c, maxlen, i, preprocessor_flag, buflen = *pbuflen; int trunc_flag = 0, seen_comment = 0; - int seen_printable = 0, seen_ampersand = 0; + int seen_printable = 0, seen_ampersand = 0, quoted = ' '; gfc_char_t *buffer; bool found_tab = false; @@ -1502,6 +1502,18 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pb && (c == '*' || c == 'c' || c == 'd')) seen_comment = 1; + if (quoted == ' ') + { + if (c == '\'' || c == '"') + quoted = c; + } + else if (c == quoted) + quoted = ' '; + + /* Is this a free-form comment? */ + if (c == '!' && quoted == ' ') + seen_comment = 1; + /* Vendor extension: "1" marks a continuation line. */ if (found_tab) { @@ -1550,17 +1562,33 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pb } else if (i >= maxlen) { + bool trunc_warn = true; + + /* Enhancement, if the very next non-space character is an ampersand + or comment that we would otherwise warn about, don't mark as + truncated. */ + /* Truncate the rest of the line. */ for (;;) { c = getc (input); - if (c == '\r') + if (c == '\r' || c == ' ') continue; if (c == '\n' || c == EOF) break; - trunc_flag = 1; + if (!trunc_warn && c != '!') + trunc_warn = true; + + if (trunc_warn && (c == '&' || c == '!')) + trunc_warn = false; + + if (c == '!') + seen_comment = 1; + + if (trunc_warn && !seen_comment) + trunc_flag = 1; } c = '\n';