From: Steven G. Kargl Date: Thu, 3 Oct 2019 20:46:26 +0000 (+0000) Subject: re PR fortran/91497 (-Wconversion warns when doing explicit type conversion) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e23390d29e19a8a6aea06fd3c4cc3990c9977ac8;p=gcc.git re PR fortran/91497 (-Wconversion warns when doing explicit type conversion) 2019-10-03 Steven G. Kargl PR fortran/91497 * simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real, gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra warnings for explicit conversion of literal constants. 2019-10-03 Steven G. Kargl PR fortran/91497 * gfortran.dg/pr91497.f90: New test. From-SVN: r276532 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f7414b6786f..9a2a800408b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-10-03 Steven G. Kargl + + PR fortran/91497 + * simplify.c (gfc_simplify_dble, simplify_intconv, gfc_simplify_real, + gfc_simplify_sngl): Disable -Wconversion and -Wconversion-extra + warnings for explicit conversion of literal constants. + 2019-10-03 Bernd Edlinger * primary.c (match_real_constant): Remove shadowing local vars. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 32ebcc04121..8c1577ec269 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -2189,11 +2189,22 @@ gfc_expr * gfc_simplify_dble (gfc_expr *e) { gfc_expr *result = NULL; + int tmp1, tmp2; if (e->expr_type != EXPR_CONSTANT) return NULL; + /* For explicit conversion, turn off -Wconversion and -Wconversion-extra + warnings. */ + tmp1 = warn_conversion; + tmp2 = warn_conversion_extra; + warn_conversion = warn_conversion_extra = 0; + result = gfc_convert_constant (e, BT_REAL, gfc_default_double_kind); + + warn_conversion = tmp1; + warn_conversion_extra = tmp2; + if (result == &gfc_bad_expr) return &gfc_bad_expr; @@ -3572,6 +3583,7 @@ static gfc_expr * simplify_intconv (gfc_expr *e, int kind, const char *name) { gfc_expr *result = NULL; + int tmp1, tmp2; /* Convert BOZ to integer, and return without range checking. */ if (e->ts.type == BT_BOZ) @@ -3585,7 +3597,17 @@ simplify_intconv (gfc_expr *e, int kind, const char *name) if (e->expr_type != EXPR_CONSTANT) return NULL; + /* For explicit conversion, turn off -Wconversion and -Wconversion-extra + warnings. */ + tmp1 = warn_conversion; + tmp2 = warn_conversion_extra; + warn_conversion = warn_conversion_extra = 0; + result = gfc_convert_constant (e, BT_INTEGER, kind); + + warn_conversion = tmp1; + warn_conversion_extra = tmp2; + if (result == &gfc_bad_expr) return &gfc_bad_expr; @@ -6472,7 +6494,7 @@ gfc_expr * gfc_simplify_real (gfc_expr *e, gfc_expr *k) { gfc_expr *result = NULL; - int kind; + int kind, tmp1, tmp2; /* Convert BOZ to real, and return without range checking. */ if (e->ts.type == BT_BOZ) @@ -6500,7 +6522,17 @@ gfc_simplify_real (gfc_expr *e, gfc_expr *k) if (e->expr_type != EXPR_CONSTANT) return NULL; + /* For explicit conversion, turn off -Wconversion and -Wconversion-extra + warnings. */ + tmp1 = warn_conversion; + tmp2 = warn_conversion_extra; + warn_conversion = warn_conversion_extra = 0; + result = gfc_convert_constant (e, BT_REAL, kind); + + warn_conversion = tmp1; + warn_conversion_extra = tmp2; + if (result == &gfc_bad_expr) return &gfc_bad_expr; @@ -7551,11 +7583,22 @@ gfc_expr * gfc_simplify_sngl (gfc_expr *a) { gfc_expr *result; + int tmp1, tmp2; if (a->expr_type != EXPR_CONSTANT) return NULL; + /* For explicit conversion, turn off -Wconversion and -Wconversion-extra + warnings. */ + tmp1 = warn_conversion; + tmp2 = warn_conversion_extra; + warn_conversion = warn_conversion_extra = 0; + result = gfc_real2real (a, gfc_default_real_kind); + + warn_conversion = tmp1; + warn_conversion_extra = tmp2; + return range_check (result, "SNGL"); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78a26a2518e..fdfcde25520 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-03 Steven G. Kargl + + PR fortran/91497 + * gfortran.dg/pr91497.f90: New test. + 2019-10-03 Jan Hubicka * g++.dg/tree-ssa/pr61034.C: Add --param max-inline-insns-single-O2=200. diff --git a/gcc/testsuite/gfortran.dg/pr91497.f90 b/gcc/testsuite/gfortran.dg/pr91497.f90 new file mode 100644 index 00000000000..aa06a49bf3f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91497.f90 @@ -0,0 +1,127 @@ +! { dg-do compile } +! { dg-options "-Wall" } +! Code contributed by Manfred Schwarb +! PR fortran/91497 +! +! Prior to applying the patch for this PR, the following code +! would generate numerous conversion warnings. +! +program foo + + real*4 a,aa + real*8 b,bb + real*10 c,cc + real*16 d + integer*2 e,ee + integer*4 f,ff + integer*8 g,gg + PARAMETER(a=3.1415927_4) + PARAMETER(b=3.1415927_8) + PARAMETER(c=3.1415927_10) + PARAMETER(d=3.1415927_16) + PARAMETER(e=123_2) + PARAMETER(f=123_4) + PARAMETER(g=123_8) + + aa=REAL(b) + aa=REAL(c) + aa=REAL(d) + aa=REAL(e) + aa=REAL(f) + aa=REAL(g) + aa=FLOAT(f) + aa=FLOOR(b) + aa=FLOOR(c) + aa=FLOOR(d) + aa=CEILING(b) + aa=CEILING(c) + aa=CEILING(d) + !---unknown but documented type conversions: + !!aa=FLOATI(e) + !!aa=FLOATJ(f) + !!aa=FLOATK(g) + !---documentation is wrong for sngl: + aa=SNGL(c) + aa=SNGL(d) + bb=REAL(c, kind=8) + bb=REAL(d, kind=8) + bb=DBLE(c) + bb=DBLE(d) + bb=DFLOAT(g) + bb=FLOOR(c) + bb=FLOOR(d) + bb=CEILING(c) + bb=CEILING(d) + cc=REAL(d, kind=10) + cc=FLOOR(d) + cc=CEILING(d) + + aa=AINT(b) + aa=ANINT(b) + aa=AINT(c) + aa=ANINT(c) + aa=AINT(d) + aa=ANINT(d) + bb=DINT(b) + bb=DNINT(b) + + ee=INT(a, kind=2) + ee=NINT(a, kind=2) + ee=INT(b, kind=2) + ee=NINT(b, kind=2) + ee=INT(c, kind=2) + ee=NINT(c, kind=2) + ee=INT(d, kind=2) + ee=NINT(d, kind=2) + ee=INT(f, kind=2) + ee=INT(g, kind=2) + ee=IFIX(a) + ee=IDINT(b) + ee=IDNINT(b) + ee=INT2(a) + ee=INT2(b) + ee=INT2(c) + ee=INT2(d) + ee=INT2(f) + ee=INT2(g) + + ff=INT(a, kind=4) + ff=NINT(a, kind=4) + ff=INT(b, kind=4) + ff=NINT(b, kind=4) + ff=INT(c, kind=4) + ff=NINT(c, kind=4) + ff=INT(d, kind=4) + ff=NINT(d, kind=4) + ff=INT(f, kind=4) + ff=INT(g, kind=4) + ff=IFIX(a) + ff=IDINT(b) + ff=IDNINT(b) + !---LONG not allowed anymore in gfortran 10 (?): + !!ff=LONG(a) + !!ff=LONG(b) + !!ff=LONG(c) + !!ff=LONG(d) + !!ff=LONG(g) + + gg=INT(a, kind=8) + gg=NINT(a, kind=8) + gg=INT(b, kind=8) + gg=NINT(b, kind=8) + gg=INT(c, kind=8) + gg=NINT(c, kind=8) + gg=INT(d, kind=8) + gg=NINT(d, kind=8) + gg=INT(f, kind=8) + gg=INT(g, kind=8) + gg=IFIX(a) + gg=IDINT(b) + gg=IDNINT(b) + gg=INT8(a) + gg=INT8(b) + gg=INT8(c) + gg=INT8(d) + gg=INT8(g) +end +