public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: prevent redundant integer division truncation warnings [PR108592]
Date: Mon, 30 Jan 2023 22:55:31 +0100	[thread overview]
Message-ID: <trinity-dc595eeb-4f3a-42c2-a0d5-c8454e324e38-1675115730988@3c-app-gmx-bap49> (raw)

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

Dear Fortranners,

the subject says it all: in some cases we emit redundant integer division
truncation warnings (2 or 4), where just one would have been sufficient.
This is solved by using gfc_warning instead of gfc_warning_now.

The testcase uses a suggestion by Andrew to verify that we get the
desired warning exactly once.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr108592.diff --]
[-- Type: text/x-patch, Size: 1871 bytes --]

From 8340523c8df8edd008174d44e87c0fa54b58b2c7 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 30 Jan 2023 22:46:43 +0100
Subject: [PATCH] Fortran: prevent redundant integer division truncation
 warnings [PR108592]

gcc/fortran/ChangeLog:

	PR fortran/108592
	* arith.cc (gfc_arith_divide): Emit integer division truncation
	warnings using gfc_warning instead of gfc_warning_now to prevent
	redundant messages.

gcc/testsuite/ChangeLog:

	PR fortran/108592
	* gfortran.dg/pr108592.f90: New test.
---
 gcc/fortran/arith.cc                   | 2 +-
 gcc/testsuite/gfortran.dg/pr108592.f90 | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr108592.f90

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index 6de6d21c73d..d0d1c0b03d2 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -778,7 +778,7 @@ gfc_arith_divide (gfc_expr *op1, gfc_expr *op2, gfc_expr **resultp)
 	    {
 	      char *p;
 	      p = mpz_get_str (NULL, 10, result->value.integer);
-	      gfc_warning_now (OPT_Winteger_division, "Integer division "
+	      gfc_warning (OPT_Winteger_division, "Integer division "
 			       "truncated to constant %qs at %L", p,
 			       &op1->where);
 	      free (p);
diff --git a/gcc/testsuite/gfortran.dg/pr108592.f90 b/gcc/testsuite/gfortran.dg/pr108592.f90
new file mode 100644
index 00000000000..224b1d8d1fc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108592.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! { dg-options "-Winteger-division" }
+! PR fortran/108592 - warn only once for truncation of integer division
+
+program foo
+  if (8 < (20/9)) stop 1 ! { dg-bogus "Integer division.*Integer division" }
+! { dg-message "Integer division truncated" "" { target *-*-* } .-1 }
+end program
--
2.35.3


             reply	other threads:[~2023-01-30 21:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 21:55 Harald Anlauf [this message]
2023-02-05 19:33 ` *PING* " Harald Anlauf
2023-02-05 21:46   ` Jerry D

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-dc595eeb-4f3a-42c2-a0d5-c8454e324e38-1675115730988@3c-app-gmx-bap49 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).