From patchwork Tue Jul 17 21:29:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 171562 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 D797D2C00BF for ; Wed, 18 Jul 2012 07:30:09 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343165411; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=vw59WpAmAQ+V2VGBilU61OggynA=; b=NJIxOQVnHZFlCs/ oVzPNEfcrIr4K6GrMg+eeUR++7RtpUU2Re5eFXC4Crfb7JM13UoVPlA4aOXITj/8 8cNdG27fbA/YcxCxcCk/p/jVoiW5R2m3s6QfPCbG33NG0cAqmoJbvf3xMM7780/i k1x7d4jgbLdl4YTlBD/rP+iX43XE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fda5nh41aw4DAWNckjt7EOmC0GSWFOpk9ObmiGJnOniI8KouxNKXcc5Ba65YDy r1W3OEFMT3DOYiSX3tkCLXCqqShfKeP0CgnmfcGOo9zGsbWUivIim54JUQKTU2+p skGdboPxHK/wgPAC9ES2131ddibNP7YzPr1L8vPPkM5mA=; Received: (qmail 314 invoked by alias); 17 Jul 2012 21:29:59 -0000 Received: (qmail 32765 invoked by uid 22791); 17 Jul 2012 21:29:58 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Jul 2012 21:29:36 +0000 Received: from [192.168.178.22] (port-92-204-53-225.dynamic.qsc.de [92.204.53.225]) by mx02.qsc.de (Postfix) with ESMTP id 62C4E24D3D; Tue, 17 Jul 2012 23:29:34 +0200 (CEST) Message-ID: <5005D93D.4000507@net-b.de> Date: Tue, 17 Jul 2012 23:29:33 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Mikael Morin CC: gcc patches , gfortran Subject: Re: [Fortran, Patch] Fix #line parsing References: <5005B454.9020608@net-b.de> <5005B746.4000104@sfr.fr> In-Reply-To: <5005B746.4000104@sfr.fr> 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 Mikael Morin wrote: > On 17/07/2012 20:52, Tobias Burnus wrote: >> Build and regtested on x86-64-gnu-linux. >> OK for the trunk? Sorry, I hit "Sent" a tad too early. The patch failed because it was also parsing the first few lines of a cpped file, which are, e.g., # 1 "gfortran.dg/g77/cpp4.F" # 1 "" # 1 "gfortran.dg/g77/cpp4.F" That lead to the warning: --------------------- gfortran.dg/g77/cpp4.F:6.16: Included at :1: Included at gfortran.dg/g77/cpp4.F:1: Included at gfortran.dg/g77/cpp4.F:1: data i /4hbla'/ 1 Warning: Extension: Hollerith constant at (1) --------------------- At the same time, it had also to work with gfortran.dg/g77/20010321-1.f, which is not preprocessed but contains the following lines: # 1 "20010321-1.f" # 1 "include/implicit.h" 1 3 # 3 "20010321-1.f" 2 3 The current patch is slightly uglier than the original version, but it seems to work. >> PS: I didn't include a test case; one could create one using >> -fdump-tree-original-lineno, if you think that it makes sense. > OK; I prefer with a testcase. I have now also included a test case. Thanks for the review – and sorry for asking for another review. Tobias PS: I wouldn't mind if you could review the assumed-rank patch. I know that it is rather big, but it kind of blocks me from writing other patches. I think the first external user will be Open MPI,* as MPIv3 will support assumed-rank arrays. * Draft MPIv3 http://www.unixer.de/sec/mpi-report-r1300.pdf ; draft Open MPI implementation https://bitbucket.org/jsquyres/mpi3-fortran/ 2012-07-17 Tobias Burnus PR fortran/53993 * scanner.c (preprocessor_line): Fix parsing of a "#line" which has no flags, add new parameter. (load_file): Update the call. 2012-07-17 Tobias Burnus PR fortran/53993 * gfortran.dg/debug_3.F90: New. diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index 4fad58b..56eaa48 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -1646,7 +1646,7 @@ get_file (const char *name, enum lc_reason reason ATTRIBUTE_UNUSED) initial octothorp has already been seen. */ static void -preprocessor_line (gfc_char_t *c) +preprocessor_line (gfc_char_t *c, bool ignore_line) { bool flag[5]; int i, line; @@ -1654,6 +1654,9 @@ preprocessor_line (gfc_char_t *c) gfc_file *f; int escaped, unescape; char *filename; + enum {FLAG_NEW_FILE = 1, FLAG_PREV_FILE, FLAG_SYSHEADER, FLAG_EXTERN_C}; + + /* The expected syntax is "# linenumber filename flags". */ c++; while (*c == ' ' || *c == '\t') @@ -1739,20 +1742,25 @@ preprocessor_line (gfc_char_t *c) flag[i] = true; } + /* No flag implies that one might have a new file. However, we have to skip + over the first three lines of a cpp'ed file. */ + if (!flag[FLAG_NEW_FILE] && !flag[FLAG_PREV_FILE] && !ignore_line) + flag[FLAG_NEW_FILE] = true; + /* Convert the filename in wide characters into a filename in narrow characters. */ filename = gfc_widechar_to_char (wide_filename, -1); /* Interpret flags. */ - if (flag[1]) /* Starting new file. */ + if (flag[FLAG_NEW_FILE]) /* Starting new file. */ { f = get_file (filename, LC_RENAME); add_file_change (f->filename, f->inclusion_line); current_file = f; } - if (flag[2]) /* Ending current file. */ + if (flag[FLAG_PREV_FILE]) /* Ending current file. */ { if (!current_file->up || filename_cmp (current_file->up->filename, filename) != 0) @@ -1959,12 +1967,12 @@ load_file (const char *realfilename, const char *displayedname, bool initial) if (initial && gfc_src_preprocessor_lines[0]) { - preprocessor_line (gfc_src_preprocessor_lines[0]); + preprocessor_line (gfc_src_preprocessor_lines[0], initial); free (gfc_src_preprocessor_lines[0]); gfc_src_preprocessor_lines[0] = NULL; if (gfc_src_preprocessor_lines[1]) { - preprocessor_line (gfc_src_preprocessor_lines[1]); + preprocessor_line (gfc_src_preprocessor_lines[1], initial); free (gfc_src_preprocessor_lines[1]); gfc_src_preprocessor_lines[1] = NULL; } @@ -2015,7 +2023,7 @@ load_file (const char *realfilename, const char *displayedname, bool initial) ; else { - preprocessor_line (line); + preprocessor_line (line, first_line); continue; } } --- /dev/null 2012-07-17 07:28:04.995717470 +0200 +++ gcc/gcc/testsuite/gfortran.dg/debug_3.F90 2012-07-17 21:19:34.000000000 +0200 @@ -0,0 +1,25 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original-lineno" } +! +! PR fortran/53993 +! +! Contributed by Markus Geimer +! +program dummy + write(*,*) "Starting dummy" +#line 444 "newFile.f90" + call foo + write(*,*) "Stopping dummy" +#line 455 "newFile.f90" +end program dummy +#line 16 "debug_3.F90" + +subroutine foo + write(*,*) "Hello world!" +end subroutine foo + +! { dg-final { scan-tree-dump "newFile.f90 : 444" "original" } } +! { dg-final { scan-tree-dump "newFile.f90 : 445" "original" } } +! { dg-final { scan-tree-dump "newFile.f90 : 455" "original" } } + +! { dg-final { scan-tree-dump "debug_3.F90 : 18" "original" } }