Fortran: prevent redundant integer division truncation warnings [PR108592]
Checks
Commit Message
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
Comments
Early gentle ping.
Am 30.01.23 um 22:55 schrieb Harald Anlauf via Gcc-patches:
> 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
>
On 2/5/23 11:33 AM, Harald Anlauf via Fortran wrote:
> Early gentle ping.
>
> Am 30.01.23 um 22:55 schrieb Harald Anlauf via Gcc-patches:
>> 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
>>
>
The patch is gentle enough to be OK to commit.
Thanks,
Jerry
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
@@ -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);
new file mode 100644
@@ -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