From patchwork Sat Jun 13 14:34:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 483890 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 B0F91140218 for ; Sun, 14 Jun 2015 00:34:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=CYJkAwJh; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=k/clOrXJY4kZpnF6Bo6R3iO/y18hAwMieo4e+ad/ltU9aD nMTFoXWiQIUZGUwTiYpf83iLGWw32QsodNyuDmnY2xDPLFeYe7ygDulk3MLna+fC GrzGhoNEmZq3e06rSJ1hvbmVPFdY2/KsMLT5SXWXuxsv2vJPH7aTuB2zF5uc4= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=q/dsX/VIF7SYQzERXl9AXPeXLfo=; b=CYJkAwJh/RVaNQxyh3Ho fPWduj9k/oFIANxf+9ElUxSBFg25PlCHk/MD+BMYvLy5cPxUDkuqTsCba1xNA3GJ EV4yJPKTRRD0cAHQp8Mz/LrDyv2nRuCxJW29Sr40aY/1sSQJxA539u5tRFHcVGgr L6jNxq0MubdO3BibCERkhHA= Received: (qmail 112007 invoked by alias); 13 Jun 2015 14:34:39 -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 111990 invoked by uid 89); 13 Jun 2015 14:34:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 13 Jun 2015 14:34:37 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 4AAF0123B5; Sat, 13 Jun 2015 16:34:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 4481611D7D; Sat, 13 Jun 2015 16:34:33 +0200 (CEST) Received: from [78.35.188.120] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.0.7) (envelope-from ) id 557c3f79-0b66-7f0000012729-7f000001b130-1 for ; Sat, 13 Jun 2015 16:34:33 +0200 Received: from [192.168.178.20] (xdsl-78-35-188-120.netcologne.de [78.35.188.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sat, 13 Jun 2015 16:34:31 +0200 (CEST) Message-ID: <557C3F76.2000901@netcologne.de> Date: Sat, 13 Jun 2015 16:34:30 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Warn about constant integer divisions Hello world, the attached patch emits a warning for constant integer division. While correct according to the standard, I cannot really think of a legitimate reason why people would want to write 3/5 where they could have written 0 , so my preference would be to put this under -Wconversion (like in the attached patch). However, I am open to discussion on that. It is easy enough to change. Regression-tested. Opinions? Comments? Would somebody rather have -Wconversion-extra? OK for trunk? Regards Thomas Index: arith.c =================================================================== --- arith.c (Revision 224450) +++ arith.c (Arbeitskopie) @@ -733,6 +733,15 @@ gfc_arith_divide (gfc_expr *op1, gfc_expr *op2, gf mpz_tdiv_q (result->value.integer, op1->value.integer, op2->value.integer); + + if (warn_conversion) + { + char *p; + p = mpz_get_str (NULL, 10, result->value.integer); + gfc_warning_now (OPT_Wconversion, "Integer division simplifies " + "to constant %qs at %L", p, &op1->where); + free (p); + } break; case BT_REAL: