From: dfranke Date: Mon, 10 May 2010 17:10:53 +0000 (+0000) Subject: gcc/fortran/: X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=3ca9b7250f3a75a486afc8fa70da6eccb1539cf5 gcc/fortran/: 2010-05-10 Daniel Franke PR fortran/27866 PR fortran/35003 PR fortran/42809 * intrinsic.c (gfc_convert_type_warn): Be more discriminative about conversion warnings. gcc/testsuite/: 2010-05-08 Daniel Franke PR fortran/27866 PR fortran/35003 PR fortran/42809 * gfortran.dg/array_constructor_type_17.f03: Updated match string. * gfortran.dg/warn_conversion.f90: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159238 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d168a3b44aa..af70b8c67a6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2010-05-10 Daniel Franke + + PR fortran/27866 + PR fortran/35003 + PR fortran/42809 + * intrinsic.c (gfc_convert_type_warn): Be more dicsriminative + about conversion warnings. + 2010-05-10 Janus Weil PR fortran/44044 diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index e8041eb9b9a..07867541be0 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -4016,8 +4016,40 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag) gfc_warning_now ("Extension: Conversion from %s to %s at %L", gfc_typename (&from_ts), gfc_typename (ts), &expr->where); else if (wflag && gfc_option.warn_conversion) - gfc_warning_now ("Conversion from %s to %s at %L", - gfc_typename (&from_ts), gfc_typename (ts), &expr->where); + { + /* If the types are the same (but not LOGICAL), and if from-kind + is larger than to-kind, this may indicate a loss of precision. + The same holds for conversions from REAL to COMPLEX. */ + if (((from_ts.type == ts->type && from_ts.type != BT_LOGICAL) + && from_ts.kind > ts->kind) + || ((from_ts.type == BT_REAL && ts->type == BT_COMPLEX) + && from_ts.kind > ts->kind)) + gfc_warning_now ("Possible loss of precision in conversion " + "from %s to %s at %L", gfc_typename (&from_ts), + gfc_typename (ts), &expr->where); + + /* If INTEGER is converted to REAL/COMPLEX, this is generally ok if + the kind of the INTEGER value is less or equal to the kind of the + REAL/COMPLEX one. Otherwise the value may not fit. + Assignment of an overly large integer constant also generates + an overflow error with range checking. */ + else if (from_ts.type == BT_INTEGER + && (ts->type == BT_REAL || ts->type == BT_COMPLEX) + && from_ts.kind > ts->kind) + gfc_warning_now ("Possible loss of digits in conversion " + "from %s to %s at %L", gfc_typename (&from_ts), + gfc_typename (ts), &expr->where); + + /* If REAL/COMPLEX is converted to INTEGER, or COMPLEX is converted + to REAL we almost certainly have a loss of digits, regardless of + the respective kinds. */ + else if (((from_ts.type == BT_REAL || from_ts.type == BT_COMPLEX) + && ts->type == BT_INTEGER) + || (from_ts.type == BT_COMPLEX && ts->type == BT_REAL)) + gfc_warning_now ("Likely loss of digits in conversion from" + "%s to %s at %L", gfc_typename (&from_ts), + gfc_typename (ts), &expr->where); + } /* Insert a pre-resolved function call to the right function. */ old_where = expr->where; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index de216a3876f..f54d9c4a898 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2010-05-08 Daniel Franke + + PR fortran/27866 + PR fortran/35003 + PR fortran/42809 + * gfortran.dg/array_constructor_type_17.f03: Updated match string. + * gfortran.dg/warn_conversion.f90: New. + 2010-05-10 Michael Matz * gcc.dg/vect/fast-math-vect-reduc-8.c: New test.