From patchwork Sun Jan 22 09:47:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 718132 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 3v5qQ045qjz9sCX for ; Sun, 22 Jan 2017 20:48:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IjwnGKJf"; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=ft6lIRbXYOH14AbA/UgNfuskRkLse3O0yAX0v1B9cs0SXvv8oS fS8l46uEh0aQnNjH8CqN13XEXyO0HPI8FQSkfle1Zcq7UXHApe2VB/4TadiAp8Kc fGdP4FSQ/rpddqVUEddgqTaD6VD49M9FzwdF+JxD0Vh1jNUGwxAz3PFsg= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=sdcCY6n9tV8CBn+SHBbFiJdKRDU=; b=IjwnGKJfAZZsfpGObOL/ F68/Sq+Sgh5Sd8MF3jLB1rbMrV1OS5w7POn+P2x4yKIYZ3GUkMWXJHprOxL4VERY 7EmlcR7j3Qk41GfHR0jtpNLf9Sf4ce2UFQXtS8KKhUasW9qelKyRr725Vuk5sAv2 Q6AwWe5Eg0MvR0ud5CqEeMw= Received: (qmail 130237 invoked by alias); 22 Jan 2017 09:47:36 -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 130214 invoked by uid 89); 22 Jan 2017 09:47:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPAM_BODY, SPF_PASS autolearn=no version=3.3.2 spammy=H*Ad:U*tkoenig, clf, Koenig, koenig 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 ESMTP; Sun, 22 Jan 2017 09:47:25 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 464F413411; Sun, 22 Jan 2017 10:47:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 40D8711E01; Sun, 22 Jan 2017 10:47:20 +0100 (CET) Received: from [78.35.128.15] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 58847fa8-022c-7f0000012729-7f000001d556-1 for ; Sun, 22 Jan 2017 10:47:20 +0100 Received: from [192.168.178.20] (xdsl-78-35-128-15.netcologne.de [78.35.128.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sun, 22 Jan 2017 10:47:18 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Warn about integer**(negative integer) Message-ID: Date: Sun, 22 Jan 2017 10:47:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 Hello world, a reacent thread on c.l.f showed another common error - expecting 10**(-3) to expect something different from zero. The attached patch warns about this result if -Winteger-division is active. Why -Winteger-division? Two reasons: First, 10**(-3) ist just a shorthand for integer division. Second, I did not want to add yet another warning flag. Regression-tested. OK for trunk? Thomas 2017-01-22 Thomas Koenig * arith.c (arith_power): If simplifying integer power expression to zero, warn if -Winteger-division is given. 2017-01-22 Thomas Koenig * gfortran.dg/integer_exponentiation_7.f90: New test. Index: arith.c =================================================================== --- arith.c (Revision 244747) +++ arith.c (Arbeitskopie) @@ -874,6 +874,11 @@ arith_power (gfc_expr *op1, gfc_expr *op2, gfc_exp { /* if op2 < 0, op1**op2 == 0 because abs(op1) > 1. */ mpz_set_si (result->value.integer, 0); + if (warn_integer_division) + gfc_warning_now (OPT_Winteger_division, "Integer " + "exponentiation truncated to constant " + "%qs at %L", "0", &result->where); + } else if (gfc_extract_int (op2, &power)) {