arith.c (arith_power): If simplifying integer power expression to zero...
authorThomas Koenig <tkoenig@netcologne.de>
Mon, 23 Jan 2017 19:43:28 +0000 (19:43 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 23 Jan 2017 19:43:28 +0000 (19:43 +0000)
2017-01-23  Thomas Koenig  <tkoenig@netcologne.de>

* arith.c (arith_power):  If simplifying integer power expression
to zero, warn if -Winteger-division is given.

2017-01-23  Thomas Koenig  <tkoenig@netcologne.de>

* gfortran.dg/integer_exponentiation_7.f90:  New test.

From-SVN: r244830

gcc/fortran/ChangeLog
gcc/fortran/arith.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/integer_exponentiation_7.f90 [new file with mode: 0644]

index b3b883fdf430c8c7330962c78bc910aa751c2b62..d6ebd797b8c97a70b35591867fa16587ebeb7be8 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-23  Thomas Koenig  <tkoenig@netcologne.de>
+
+       * arith.c (arith_power):  If simplifying integer power expression
+       to zero, warn if -Winteger-division is given.
+
 2017-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/79154
index 9d14487237ff465cf91318ef7fc47bd4095c7df8..8fa305c6aee2a915ed00cbb35ed17411abce1f04 100644 (file)
@@ -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))
                  {
index 5bdeda872232b8356157ef0ccceb557fe5c67b9b..10c34ccc6c4ac3c766f95d67786de60152fe8e11 100644 (file)
@@ -1,3 +1,7 @@
+2017-01-23  Thomas Koenig  <tkoenig@netcologne.de>
+
+       * gfortran.dg/integer_exponentiation_7.f90:  New test.
+
 2017-01-23  Bernd Schmidt  <bschmidt@redhat.com>
 
        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 (file)
index 0000000..fde2219
--- /dev/null
@@ -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