Bug 40290 - Spurious warning on REAL*COMPLEX with -Wconversion
Summary: Spurious warning on REAL*COMPLEX with -Wconversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-29 11:20 UTC by Harald Anlauf
Modified: 2009-12-11 21:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-12-10 21:46:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2009-05-29 11:20:40 UTC
Hi,

the following warning appears questionable:

subroutine gfcbug87
  implicit none
  real    :: x
  complex :: c
  c = c * x
end subroutine gfcbug87


gfcbug87.f90:5.11:

  c = c * x
           1
Warning: Conversion from REAL(4) to COMPLEX(4) at (1)


There are really no kind conversions involved.  In fact, I do even hope
that the optimizer knowns that REAL*COMPLEX is a much cheaper operation
than the full COMPLEX*COMPLEX implied by the warning.
Comment 1 Daniel Franke 2009-12-10 21:46:21 UTC
Actually, the program

  real    :: x
  complex :: c
  c = c * x
end

is directly translated to ...

MAIN__ ()
{
  complex(kind=4) c;
  real(kind=4) x;

  c = COMPLEX_EXPR <x, 0.0> * c;
}

... and yukka, the "optimized" dump has ...

  real(kind=4) D.1522;
  real(kind=4) D.1521;
  real(kind=4) D.1520;
  real(kind=4) D.1519;
  real(kind=4) D.1518;
  real(kind=4) D.1517;
  real(kind=4) D.1516;
  real(kind=4) D.1515;
  real(kind=4) D.1514;
  real(kind=4) D.1513;
  real(kind=4) x;
  complex(kind=4) c;
  complex(kind=4) c.2;
  complex(kind=4) c.1;
  complex(kind=4) D.1510;

<bb 2>:
  D.1510_2 = COMPLEX_EXPR <x_1(D), 0.0>;
  c.1_3 = c;
  D.1513_4 = REALPART_EXPR <D.1510_2>;
  D.1514_5 = IMAGPART_EXPR <D.1510_2>;
  D.1515_6 = REALPART_EXPR <c.1_3>;
  D.1516_7 = IMAGPART_EXPR <c.1_3>;
  D.1517_8 = D.1513_4 * D.1515_6;
  D.1518_9 = D.1514_5 * D.1516_7;
  D.1519_10 = D.1513_4 * D.1516_7;
  D.1520_11 = D.1514_5 * D.1515_6;
  D.1521_12 = D.1517_8 - D.1518_9;
  D.1522_13 = D.1519_10 + D.1520_11;
  c.2_14 = COMPLEX_EXPR <D.1521_12, D.1522_13>;
  c = c.2_14;
  return;
Comment 2 Daniel Franke 2009-12-11 18:56:55 UTC
Using "-O3 -fno-signed-zeros" (the latter being set by -ffast-math) gets rid of all the additional computations and results in

<bb 2>:
  D.1504_2 = *a_1(D);
  D.1514_10 = REALPART_EXPR <*b_4(D)>;
  D.1515_11 = IMAGPART_EXPR <*b_4(D)>;
  D.1516_12 = D.1504_2 * D.1514_10;
  D.1517_13 = D.1504_2 * D.1515_11;
  __result_op.0_6 = COMPLEX_EXPR <D.1516_12, D.1517_13>;
  return __result_op.0_6;


With the patch below, the warning would be disabled. However is this warning a feature (then keep it), or an artefact of an implementation detail (then remove it)?

Index: expr.c
===================================================================
--- expr.c      (revision 155148)
+++ expr.c      (working copy)
@@ -720,9 +720,9 @@ gfc_type_convert_binary (gfc_expr *e)
   else
     e->ts.kind = op2->ts.kind;
   if (op1->ts.type != BT_COMPLEX || op1->ts.kind != e->ts.kind)
-    gfc_convert_type (e->value.op.op1, &e->ts, 2);
+    gfc_convert_type_warn (e->value.op.op1, &e->ts, 2, 0);
   if (op2->ts.type != BT_COMPLEX || op2->ts.kind != e->ts.kind)
-    gfc_convert_type (e->value.op.op2, &e->ts, 2);
+    gfc_convert_type_warn (e->value.op.op2, &e->ts, 2, 0);

 done:
   return;
Comment 3 Daniel Franke 2009-12-11 21:08:54 UTC
Subject: Bug 40290

Author: dfranke
Date: Fri Dec 11 21:08:39 2009
New Revision: 155179

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155179
Log:
2009-12-11  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/40290
        * expr.c (gfc_type_convert_binary): Added warn-on-conversion flag,
        passed on to gfc_convert_type_warn() instead of gfc_convert_type();
        enabled warnings on all callers but ...
        * arith.c (eval_intrinsic): Disabled warnings on implicit type
        conversion.
        * gfortran.h gfc_type_convert_binary): Adjusted prototype.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/resolve.c

Comment 4 Daniel Franke 2009-12-11 21:10:07 UTC
Fixed in trunk. Closing.
Thanks for the report!