From patchwork Mon Nov 14 13:51:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 82109 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1017570qge; Mon, 14 Nov 2016 05:52:05 -0800 (PST) X-Received: by 10.99.52.10 with SMTP id b10mr29494934pga.42.1479131525013; Mon, 14 Nov 2016 05:52:05 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d9si22294670pgg.140.2016.11.14.05.52.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2016 05:52:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441357-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-441357-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441357-patch=linaro.org@gcc.gnu.org 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:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=Tphzdr0EJcdfd8k3b OLVvQLU05HYqEXH837VwSTyzNY2hnU9FS2+aQ08kPmowUf/qpcwiI4VioOC2nrd1 mnn0N/R4kWuzBt2+oj7MOapzKV+a87C4PJQMt7X8wt5Xm9QdE4rvpApn+6sz+sfY v2mea1G5e9Nq17+6wQKI7oZQCE= 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:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=vxDx8WSwNWpSWP1coUB6hkT 9VVE=; b=yCijcH0arWhNea7MYBZTG8cw4jQ6i0VaQVdwzhE4Qhax2ltWbilM+ib Jcp9UTpt1oVFQy+jULByKaMMKNrML9up0VVQkD7301tnw2tSbZcizZZA61QjYKCU Xa+GtfSIUHR189mFABbvht8H0vlmS+TOlUKTuxBmP23HRmJ0vdMQ= Received: (qmail 108104 invoked by alias); 14 Nov 2016 13:51:46 -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 108085 invoked by uid 89); 14 Nov 2016 13:51:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=127, 6, *walk_subtrees, H*i:sk:4969b39, H*f:sk:4969b39 X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Nov 2016 13:51:35 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 5918E12864; Mon, 14 Nov 2016 14:51:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 4AB2911DBC; Mon, 14 Nov 2016 14:51:33 +0100 (CET) Received: from [78.35.170.112] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 5829c165-022c-7f0000012729-7f000001b19d-1 for ; Mon, 14 Nov 2016 14:51:33 +0100 Received: from [192.168.178.20] (xdsl-78-35-170-112.netcologne.de [78.35.170.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Mon, 14 Nov 2016 14:51:32 +0100 (CET) Subject: Re: [Patch, fortran, RFC] Add warning for missing location information To: "fortran@gcc.gnu.org" , gcc-patches References: <4969b391-c8ec-4eb4-1cb7-d43d0013834d@netcologne.de> From: Thomas Koenig Message-ID: Date: Mon, 14 Nov 2016 14:51:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <4969b391-c8ec-4eb4-1cb7-d43d0013834d@netcologne.de> > the attached patch runs through gfortran's AST to check for missing > location information. ... this time with attachment. 2016-11-14 Thomas Koenig PR fortran/78226 * error.c (gfc_warning_internal): New function. * frontend-passes.c (CHECK_LOCUS): New macro. (gfc_run_passes): Call check_locus if CHECK_LOCUS is defined. (check_locus_code): New function. (check_locus_expr): New function. (check_locus): New function. * gfortran.h: Add prototype for gfc_warning_internal. Index: error.c =================================================================== --- error.c (Revision 242335) +++ error.c (Arbeitskopie) @@ -1160,7 +1160,25 @@ gfc_warning_now (int opt, const char *gmsgid, ...) return ret; } +/* Internal warning, do not buffer. */ +bool +gfc_warning_internal (int opt, const char *gmsgid, ...) +{ + va_list argp; + diagnostic_info diagnostic; + rich_location rich_loc (line_table, UNKNOWN_LOCATION); + bool ret; + + va_start (argp, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, + DK_NOTE); + diagnostic.option_index = opt; + ret = report_diagnostic (&diagnostic); + va_end (argp); + return ret; +} + /* Immediate error (i.e. do not buffer). */ void Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 242335) +++ frontend-passes.c (Arbeitskopie) @@ -27,6 +27,14 @@ along with GCC; see the file COPYING3. If not see #include "constructor.h" #include "intrinsic.h" +/* Conditional compilations. */ + +#ifdef CHECKING_P +#define CHECK_LOCUS 1 +#else +#undef CHECK_LOCUS +#endif + /* Forward declarations. */ static void strip_function_call (gfc_expr *); @@ -48,6 +56,10 @@ static gfc_code * create_do_loop (gfc_expr *, gfc_ locus *, gfc_namespace *, char *vname=NULL); +#ifdef CHECK_LOCUS +static void check_locus (gfc_namespace *); +#endif + /* How deep we are inside an argument list. */ static int count_arglist; @@ -127,6 +139,10 @@ gfc_run_passes (gfc_namespace *ns) doloop_list.release (); int w, e; +#ifdef CHECK_LOCUS + check_locus (ns); +#endif + if (flag_frontend_optimize) { optimize_namespace (ns); @@ -145,6 +161,53 @@ gfc_run_passes (gfc_namespace *ns) realloc_strings (ns); } +#ifdef CHECK_LOCUS + +/* Callback function: Warn if there is no location information in a + statement. */ + +static int +check_locus_code (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED, + void *data ATTRIBUTE_UNUSED) +{ + current_code = c; + if (c && *c && (((*c)->loc.nextc == NULL) || ((*c)->loc.lb == NULL))) + gfc_warning_internal (0, "No location in statement statement"); + + return 0; +} + +/* Callback function: Warn if there is no location information in an + expression. */ + +static int +check_locus_expr (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, + void *data ATTRIBUTE_UNUSED) +{ + + if (e && *e && (((*e)->where.nextc == NULL || (*e)->where.lb == NULL))) + gfc_warning_internal (0, "No location in expression near %L", + &((*current_code)->loc)); + return 0; + +} + +/* Run check for missing location information. */ + +static void +check_locus (gfc_namespace *ns) +{ + gfc_code_walker (&ns->code, check_locus_code, check_locus_expr, NULL); + + for (ns = ns->contained; ns; ns = ns->sibling) + { + if (ns->code == NULL || ns->code->op != EXEC_BLOCK) + check_locus (ns); + } +} + +#endif + /* Callback for each gfc_code node invoked from check_realloc_strings. For an allocatable LHS string which also appears as a variable on the RHS, replace Index: gfortran.h =================================================================== --- gfortran.h (Revision 242335) +++ gfortran.h (Arbeitskopie) @@ -2778,6 +2778,7 @@ const char *gfc_print_wide_char (gfc_char_t); bool gfc_warning (int opt, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); bool gfc_warning_now (int opt, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); +bool gfc_warning_internal (int opt, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); bool gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(3,4);