From 15b8fd499dd07627a78253ab722cc9049d86d68a Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Mon, 23 Jan 2017 19:43:28 +0000 Subject: [PATCH] arith.c (arith_power): If simplifying integer power expression to zero... 2017-01-23 Thomas Koenig * arith.c (arith_power): If simplifying integer power expression to zero, warn if -Winteger-division is given. 2017-01-23 Thomas Koenig * gfortran.dg/integer_exponentiation_7.f90: New test. From-SVN: r244830 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/arith.c | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 | 5 +++++ 4 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b3b883fdf43..d6ebd797b8c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2017-01-23 Thomas Koenig + + * arith.c (arith_power): If simplifying integer power expression + to zero, warn if -Winteger-division is given. + 2017-01-22 Jakub Jelinek PR fortran/79154 diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c index 9d14487237f..8fa305c6aee 100644 --- a/gcc/fortran/arith.c +++ b/gcc/fortran/arith.c @@ -874,6 +874,10 @@ arith_power (gfc_expr *op1, gfc_expr *op2, gfc_expr **resultp) { /* 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, "Negative " + "exponent of integer has zero " + "result at %L", &result->where); } else if (gfc_extract_int (op2, &power)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5bdeda87223..10c34ccc6c4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-01-23 Thomas Koenig + + * gfortran.dg/integer_exponentiation_7.f90: New test. + 2017-01-23 Bernd Schmidt PR rtl-optimization/78634 diff --git a/gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 b/gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 new file mode 100644 index 00000000000..fde221938ff --- /dev/null +++ b/gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 @@ -0,0 +1,5 @@ +! { dg-do compile } +! { dg-options "-Winteger-division" } +program main + print *,10**(-3) ! { dg-warning "Negative exponent of integer has zero result" } +end program main -- 2.30.2