From patchwork Sun Aug 19 10:31:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 178555 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 B12512C0089 for ; Sun, 19 Aug 2012 20:32:16 +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=1345977138; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=StqAhmF NgKHwYdVrQYrQOm6l63c=; b=T1aT27VSjBrP9PB6Rg+l5PKOM9VnnhPNQoYuigg RUhTNN8zfbmfi9GWWLTjC2oitCPdneYXsjquPgy0M5FaE2KSU1bgMWO5loKH1USa Rfnm6YxvVmFYIwlX1axQm8s6XQXnyRikjryWQ8RjwzXWDKBjaD7yLmZmT7/Ta5RQ vzYE= 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:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=tkdtBgTiUu977QV8uQAk8r3qLZjDzoywoYeLSFaYffa6pnOj27Jfs4fYP3YtF3 XX9IPVRP1d8XlyjglS1Em+TAycw8UEtr/qZLFUFqcS1SEAG7Icca7fwztncI00fj v4F2t5UTITrjxDEIZneLfThK7CPr2EfAcUQyOGxS/FyuU=; Received: (qmail 12145 invoked by alias); 19 Aug 2012 10:32:06 -0000 Received: (qmail 12120 invoked by uid 22791); 19 Aug 2012 10:32:03 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 19 Aug 2012 10:31:49 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id D932C125EF; Sun, 19 Aug 2012 12:31:45 +0200 (CEST) Received: from [192.168.0.108] (xdsl-78-35-148-63.netcologne.de [78.35.148.63]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id A610B11D9B; Sun, 19 Aug 2012 12:31:44 +0200 (CEST) Message-ID: <5030C08F.9000300@netcologne.de> Date: Sun, 19 Aug 2012 12:31:43 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Warning for feal / complex equality / inequality comparisons 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 Hello world, the attached patch warns about comparisions for equality and inequality of real and complex values if -Wcompare-reals is given. The new compiler option is included in -Wall. Regression-tested, tested with "make info" and "make dvi". OK for trunk? Thomas 2012-08-19 Thomas König PR fortran/54298 * gfortran.h (struct gfc_option_t): Add warn_compare_reals. * lang.opt: Add Wcompare-reals. * invoke.texi: Document -Wcompare-reals. * resolve.c (resolve_operator): If -Wcompare-reals is in effect, warn about equality/inequality comparisions for REAL and COMPLEX. * options.c (gfc_init_options): Set warn_compare_reals. (set_Wall): Include warn_compare_reals in Wall. (gfc_handle_option): Handle Wcompare_reals. 2012-08-19 Thomas König PR fortran/54298 * gfortran.dg/real_compare_1.f90: New test case. * gfortran.dg/bessel_5.f90 Add -Wno-compare-reals to options. Index: testsuite/gfortran.dg/bessel_5.f90 =================================================================== --- testsuite/gfortran.dg/bessel_5.f90 (Revision 190442) +++ testsuite/gfortran.dg/bessel_5.f90 (Arbeitskopie) @@ -1,5 +1,5 @@ ! { dg-do run } -! { dg-options "-Wall -fno-range-check" } +! { dg-options "-Wall -fno-range-check -Wno-compare-reals" } ! ! PR fortran/36158 - Transformational BESSEL_JN/YN ! PR fortran/33197 - F2008 math functions Index: fortran/gfortran.h =================================================================== --- fortran/gfortran.h (Revision 190442) +++ fortran/gfortran.h (Arbeitskopie) @@ -2225,6 +2225,7 @@ typedef struct int warn_unused_dummy_argument; int warn_realloc_lhs; int warn_realloc_lhs_all; + int warn_compare_reals; int max_errors; int flag_all_intrinsics; Index: fortran/lang.opt =================================================================== --- fortran/lang.opt (Revision 190442) +++ fortran/lang.opt (Arbeitskopie) @@ -218,6 +218,10 @@ Wcharacter-truncation Fortran Warning Warn about truncated character expressions +Wcompare-reals +Fortran Warning +Warn about equality comparisons involving REAL or COMPLEX expressions + Wconversion Fortran Warning ; Documented in C Index: fortran/invoke.texi =================================================================== --- fortran/invoke.texi (Revision 190442) +++ fortran/invoke.texi (Arbeitskopie) @@ -726,10 +726,11 @@ warnings. @cindex warnings, all Enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. -This currently includes @option{-Waliasing}, @option{-Wampersand}, -@option{-Wconversion}, @option{-Wsurprising}, @option{-Wintrinsics-std}, -@option{-Wno-tabs}, @option{-Wintrinsic-shadow}, @option{-Wline-truncation}, -@option{-Wreal-q-constant} and @option{-Wunused}. +This currently includes @option{-Waliasing}, @option{-Wampersand}, +@option{-Wconversion}, @option{-Wcompare-reals}, @option{-Wsurprising}, +@option{-Wintrinsics-std}, @option{-Wno-tabs}, @option{-Wintrinsic-shadow}, +@option{-Wline-truncation}, @option{-Wreal-q-constant} and +@option{-Wunused}. @item -Waliasing @opindex @code{Waliasing} @@ -935,6 +936,11 @@ a scalar. See also @option{-frealloc-lhs}. Warn when the compiler inserts code to for allocation or reallocation of an allocatable variable; this includes scalars and derived types. +@item -Wcompare-reals +@opindex @code{Wcompare-reals} +Warn when comparing real or complex types for equality or inequality. +Enabled by @option{-Wall}. + @item -Werror @opindex @code{Werror} @cindex warnings, to errors Index: fortran/resolve.c =================================================================== --- fortran/resolve.c (Revision 190442) +++ fortran/resolve.c (Arbeitskopie) @@ -4034,6 +4034,27 @@ resolve_operator (gfc_expr *e) e->ts.type = BT_LOGICAL; e->ts.kind = gfc_default_logical_kind; + + if (gfc_option.warn_compare_reals) + { + gfc_intrinsic_op op = e->value.op.op; + + if ((op1->ts.type == BT_REAL || op1->ts.type == BT_COMPLEX) + && (op == INTRINSIC_EQ || op == INTRINSIC_EQ_OS + || op == INTRINSIC_NE || op == INTRINSIC_NE_OS)) + { + bool equality; + + equality = op == INTRINSIC_EQ || op == INTRINSIC_EQ_OS; + + /* Type conversion has made sure that the types + of op1 and op2 agree. */ + gfc_warning ("%s comparison for %s at %L", + equality ? "Equality" : "Inequality", + gfc_typename (&op1->ts), &op1->where); + } + } + break; } Index: fortran/options.c =================================================================== --- fortran/options.c (Revision 190442) +++ fortran/options.c (Arbeitskopie) @@ -113,6 +113,7 @@ gfc_init_options (unsigned int decoded_options_cou gfc_option.warn_unused_dummy_argument = 0; gfc_option.warn_realloc_lhs = 0; gfc_option.warn_realloc_lhs_all = 0; + gfc_option.warn_compare_reals = 0; gfc_option.max_errors = 25; gfc_option.flag_all_intrinsics = 0; @@ -473,6 +474,7 @@ set_Wall (int setting) gfc_option.warn_character_truncation = setting; gfc_option.warn_real_q_constant = setting; gfc_option.warn_unused_dummy_argument = setting; + gfc_option.warn_compare_reals = setting; warn_return_type = setting; warn_switch = setting; @@ -638,6 +640,10 @@ gfc_handle_option (size_t scode, const char *arg, gfc_option.warn_character_truncation = value; break; + case OPT_Wcompare_reals: + gfc_option.warn_compare_reals = value; + break; + case OPT_Wconversion: gfc_option.gfc_warn_conversion = value; break;