From patchwork Fri May 4 19:32:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 909015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477267-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vN6K0faL"; dkim-atps=neutral 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 40d2G66YQmz9s2t for ; Sat, 5 May 2018 05:32:13 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=abuppAvL2gqr5tMZb3luFAjfnnmMQfnBblGd9B7QvwxGWgXJs4 jCAJHq+MyTpgeC43XMTs1+RPH/ds2X3lFvQIwAbQvGtNPXFaNZwi7coFSY4Omszx Ywl6UtVpKL6nj7wFdVT3CDfOtnbaLBHfhmLUAoefNdP0mcbWYsxdqjV7A= 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:from :to:cc:subject:message-id:date:mime-version:content-type; s= default; bh=c1Cg1tTaZrAINqoXQ9hcZiYLNno=; b=vN6K0faLjU1u6sn6wHvc Hyjuun+bJHLOVtg0WRffRGef0PS3JP/t0Y8LWVBRJY2ar7IL2P43QR4EkARZB59p YwVyMu8sGhB+a82e4rEuhErP7aj8mIQFslAvZ+RJSJFb/wARA+9ZvYGSXEkk2A00 OvsADmd07otdnX8LNAh24L0= Received: (qmail 9711 invoked by alias); 4 May 2018 19:32: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 9677 invoked by uid 89); 4 May 2018 19:32:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2399 X-Spam-User: qpsmtpd, 2 recipients 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 ESMTP; Fri, 04 May 2018 19:32:04 +0000 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5092D13AAE; Fri, 4 May 2018 19:32:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-53.rdu2.redhat.com [10.10.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 910952016761; Fri, 4 May 2018 19:32:01 +0000 (UTC) From: Jeff Law Openpgp: preference=signencrypt Autocrypt: addr=law@redhat.com; prefer-encrypt=mutual; keydata= xsBNBFkbIO8BCACVIqDhDVh9ur8C+zNV1J/cXfwvVDAUcphDEFl4jyHqZORK4Pd3Db8oWqLm Q8lOCr/VOS7lrCtdpVMQkLGOGA16oJ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SBrYp4kG3dfIXE+wSSvE7qPABEBAAHCwHYEGAEIACAW IQR+niGjtnP5P/8PpRq8fP682pgzWwUCWRsg7wIbDAAKCRC8fP682pgzW3REB/9cT7iKRPg/ OK9bpLlllIEDM90IaKC79DQrv+fRudOR78cdV4XUwPSFnyHUsP3VJ4lDy5FhiKCwGie0BK53 EsxgMrLy1L8hboFdTE4Vi0xzCheMaMVp4hATDU29k1cuxu1VPpCa8E3mYeHjNV7ip0HN5L4D rfs8lRPJE/oM1vGs9DgQFZrCPPNRNGKC97BH+DHccesEJr7tSsQrkPkt0z/FTKr5wIM02vSx OJjgmcVbGB7dc2j/Sx8loXmuKnuKtM35668kUG8jeJvSQk3o/VHpD27bhl0rR68R2jN6G6kQ egMVb6dPu1Ius8rBE5rFw88J4JEb5q4hMNClWWUFHIdP To: gfortran Cc: gcc-patches Subject: [RFA][fortran] Fix # handling in the Fortran front-end Message-ID: <704e1a86-f096-9418-818b-d0d322a8c1f5@redhat.com> Date: Fri, 4 May 2018 13:32:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-IsSubscribed: yes The Fortran front end has its own code to parse # directives. We've run into a case where it does not function correctly. In particular when the directive changes the current file, subsequent diagnostics still refer to the original filename. Concretely take this code and compile it with -Wall: # 12345 "foo-f" SUBROUTINE s(dummy) INTEGER, INTENT(in) :: dummy END SUBROUTINE The "dummy" argument is unused and you'll get a diagnostic like: -bash-4.3$ gfortran j.f90 -Wall j.f90:12345:18: Warning: Unused dummy argument ‘dummy’ at (1) [-Wunused-dummy-argument] Note how we got the right line #, but the wrong file in the diagnostic. It should look something like this: [law@torsion gcc]$ ./gfortran -Wall -B./ j.f90 foo-f:12345:18: Warning: Unused dummy argument ‘dummy’ at (1) [-Wunused-dummy-argument] --- AFAICT the Fortran front-end has failed to notify the linemap interface that the current filename has changed. This patch (and testcase) fixes the problem by adding the missing call to linemap_add. Bootstrapped and regression tested on x86_64-linux-gnu. OK for the trunk? Jeff diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index aab5379..55d6daf 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -2107,6 +2107,10 @@ preprocessor_line (gfc_char_t *c) in the linemap. Alternative could be using GC or updating linemap to point to the new name, but there is no API for that currently. */ current_file->filename = xstrdup (filename); + + /* We need to tell the linemap API that the filename changed. Just + changing current_file is insufficient. */ + linemap_add (line_table, LC_RENAME, false, current_file->filename, line); } /* Set new line number. */ diff --git a/gcc/testsuite/gfortran.dg/linefile.f90 b/gcc/testsuite/gfortran.dg/linefile.f90 new file mode 100644 index 0000000..7f1465a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/linefile.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-Wall" } + +# 4 "foo-f" +SUBROUTINE s(dummy) + INTEGER, INTENT(in) :: dummy +END SUBROUTINE +! We want to check that the # directive changes the filename in the +! diagnostic. Nothing else really matters here. dg-regexp allows us +! to see the entire diagnostic. We just have to make sure to consume +! the entire message. +! { dg-regexp "foo-f\[^\n]*" }