public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition
@ 2006-07-19 16:59 mfpasik at sandia dot gov
2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: mfpasik at sandia dot gov @ 2006-07-19 16:59 UTC (permalink / raw)
To: gcc-bugs
The expression/condition in an arithmetic if statement appears to be evaluated
multiple times when it is zero or negative. This is particularly bad when the
expression is a function that depends on input or has state associated with it.
Example:
program lll
integer myfunc
do 99 i=1,10
if (myfunc(0)) 10,20,30
10 write (6,*) 'negative'
goto 99
20 write (6,*) 'zero'
goto 99
30 write (6,*) 'positive'
goto 99
99 continue
end
integer function myfunc(int)
integer value
read (5,*) value
myfunc = value
return
end
Sample input/output:
1
positive
0
3
zero
-1
3
zero
4
positive
0
0
zero
Workaround:
Introduce a temporary expression for the if test condition/expression or
convert obsolete arithmetic if to an if-then-else statement.
--
Summary: Multiple evaluations of arithmetic if condition
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mfpasik at sandia dot gov
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
@ 2006-07-19 20:33 ` kargl at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-19 20:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from kargl at gcc dot gnu dot org 2006-07-19 20:33 -------
Yep. The dump-tree-original contains
if (myfunc (&C.1243) <= 0)
{
if (myfunc (&C.1243) < 0) goto __label_000010;
else goto __label_000020;
}
else
{
goto __label_000030;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
@ 2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: steven at gcc dot gnu dot org @ 2006-07-19 23:03 UTC (permalink / raw)
To: gcc-bugs
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-07-19 23:03:44
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
@ 2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:06 ` pinskia at gcc dot gnu dot org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: steven at gcc dot gnu dot org @ 2006-07-19 23:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from steven at gcc dot gnu dot org 2006-07-19 23:03 -------
Wrong code. Bad.
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |major
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (2 preceding siblings ...)
2006-07-19 23:03 ` steven at gcc dot gnu dot org
@ 2006-07-19 23:06 ` pinskia at gcc dot gnu dot org
2006-07-19 23:08 ` steven at gcc dot gnu dot org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-07-19 23:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-07-19 23:06 -------
The easiest way to fix this is most likely wrap the function call in a
SAVE_EXPR but I could be wrong.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (3 preceding siblings ...)
2006-07-19 23:06 ` pinskia at gcc dot gnu dot org
@ 2006-07-19 23:08 ` steven at gcc dot gnu dot org
2006-07-20 4:37 ` kargl at gcc dot gnu dot org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: steven at gcc dot gnu dot org @ 2006-07-19 23:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from steven at gcc dot gnu dot org 2006-07-19 23:08 -------
Andrew, you're wrong. :-P
My gfortran skills are not what they used to be, but I believe this is the fix:
Index: trans-stmt.c
===================================================================
--- trans-stmt.c (revision 115467)
+++ trans-stmt.c (working copy)
@@ -663,6 +663,7 @@ gfc_trans_arithmetic_if (gfc_code * code
/* Pre-evaluate COND. */
gfc_conv_expr_val (&se, code->expr);
+ se.expr = gfc_evaluate_now (se.expr, &se.pre);
/* Build something to compare with. */
zero = gfc_build_const (TREE_TYPE (se.expr), integer_zero_node);
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (4 preceding siblings ...)
2006-07-19 23:08 ` steven at gcc dot gnu dot org
@ 2006-07-20 4:37 ` kargl at gcc dot gnu dot org
2006-07-21 23:39 ` steven at gcc dot gnu dot org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-20 4:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from kargl at gcc dot gnu dot org 2006-07-20 04:37 -------
(In reply to comment #4)
> My gfortran skills are not what they used to be,
You're always welcomed to spend some quality time with the
gfortran source code :-)
> but I believe this is the fix:
>
> Index: trans-stmt.c
> ===================================================================
> --- trans-stmt.c (revision 115467)
> +++ trans-stmt.c (working copy)
> @@ -663,6 +663,7 @@ gfc_trans_arithmetic_if (gfc_code * code
>
> /* Pre-evaluate COND. */
> gfc_conv_expr_val (&se, code->expr);
> + se.expr = gfc_evaluate_now (se.expr, &se.pre);
>
I think you're on the right track, but shouldn't it be
se.expr = gfc_evaluate_now (code->expr, &se.pre);
I'm not sure of the &se.pre part, yet.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (5 preceding siblings ...)
2006-07-20 4:37 ` kargl at gcc dot gnu dot org
@ 2006-07-21 23:39 ` steven at gcc dot gnu dot org
2006-07-22 2:01 ` kargl at gcc dot gnu dot org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: steven at gcc dot gnu dot org @ 2006-07-21 23:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from steven at gcc dot gnu dot org 2006-07-21 23:39 -------
The definition of gfc_evaluate_now is:
trans.h:tree gfc_evaluate_now (tree, stmtblock_t *);
And the effect of adding &se.pre is to add the code to the block. You can see
this going on everywhere in gfortran with a simple grep in the source code.
So the use "se.expr = gfc_evaluate_now (code->expr, &se.pre);" is correct. I
actually even tested it, you know ;-)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (6 preceding siblings ...)
2006-07-21 23:39 ` steven at gcc dot gnu dot org
@ 2006-07-22 2:01 ` kargl at gcc dot gnu dot org
2006-07-22 17:55 ` kargl at gcc dot gnu dot org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-22 2:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from kargl at gcc dot gnu dot org 2006-07-22 02:01 -------
Steven,
I believe you're correct. I misread your patch where I thought
you were replacing the line above the one you added. Sorry about
the noise. I'll test and commit the patch.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (7 preceding siblings ...)
2006-07-22 2:01 ` kargl at gcc dot gnu dot org
@ 2006-07-22 17:55 ` kargl at gcc dot gnu dot org
2006-07-22 17:58 ` [Bug fortran/28439] [4.1 only] " kargl at gcc dot gnu dot org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-22 17:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from kargl at gcc dot gnu dot org 2006-07-22 17:55 -------
Subject: Bug 28439
Author: kargl
Date: Sat Jul 22 17:55:35 2006
New Revision: 115677
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115677
Log:
2006-07-22 Steven Bosscher <steven@gcc.gnu.org>
PR fortran/28439
* trans-stmt.c (gfc_trans_arithmetic_if): Evaluate the condition once.
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-stmt.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] [4.1 only] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (8 preceding siblings ...)
2006-07-22 17:55 ` kargl at gcc dot gnu dot org
@ 2006-07-22 17:58 ` kargl at gcc dot gnu dot org
2006-07-24 16:54 ` kargl at gcc dot gnu dot org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-22 17:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from kargl at gcc dot gnu dot org 2006-07-22 17:58 -------
Fixed on trunk.
--
kargl at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Multiple evaluations of |[4.1 only] Multiple
|arithmetic if condition |evaluations of arithmetic if
| |condition
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] [4.1 only] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (9 preceding siblings ...)
2006-07-22 17:58 ` [Bug fortran/28439] [4.1 only] " kargl at gcc dot gnu dot org
@ 2006-07-24 16:54 ` kargl at gcc dot gnu dot org
2006-07-25 23:31 ` kargl at gcc dot gnu dot org
2006-07-25 23:32 ` kargl at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-24 16:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from kargl at gcc dot gnu dot org 2006-07-24 16:54 -------
Subject: Bug 28439
Author: kargl
Date: Mon Jul 24 16:54:01 2006
New Revision: 115718
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115718
Log:
2006-07-24 Steven G. Kargl <kargls@comcast.net>
PR fortran/28439
* gfortran.dg/arithmetic_if.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/arithmetic_if.f90
Modified:
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] [4.1 only] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (10 preceding siblings ...)
2006-07-24 16:54 ` kargl at gcc dot gnu dot org
@ 2006-07-25 23:31 ` kargl at gcc dot gnu dot org
2006-07-25 23:32 ` kargl at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-25 23:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from kargl at gcc dot gnu dot org 2006-07-25 23:31 -------
Subject: Bug 28439
Author: kargl
Date: Tue Jul 25 23:31:16 2006
New Revision: 115743
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115743
Log:
2006-07-25 Steven G. Kargl <kargls@comcast.net>
PR fortran/28439
*trans-stmt.c (gfc_trans_arithmetic_if): Evaluate the condition once.
gfortran.dg/arithmetic_if.f90: New test.
Added:
branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/arithmetic_if.f90
Modified:
branches/gcc-4_1-branch/gcc/fortran/ChangeLog
branches/gcc-4_1-branch/gcc/fortran/trans-stmt.c
branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/28439] [4.1 only] Multiple evaluations of arithmetic if condition
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
` (11 preceding siblings ...)
2006-07-25 23:31 ` kargl at gcc dot gnu dot org
@ 2006-07-25 23:32 ` kargl at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2006-07-25 23:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from kargl at gcc dot gnu dot org 2006-07-25 23:32 -------
Fixed in 4.1
--
kargl at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.1.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28439
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2006-07-25 23:32 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-19 16:59 [Bug fortran/28439] New: Multiple evaluations of arithmetic if condition mfpasik at sandia dot gov
2006-07-19 20:33 ` [Bug fortran/28439] " kargl at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:03 ` steven at gcc dot gnu dot org
2006-07-19 23:06 ` pinskia at gcc dot gnu dot org
2006-07-19 23:08 ` steven at gcc dot gnu dot org
2006-07-20 4:37 ` kargl at gcc dot gnu dot org
2006-07-21 23:39 ` steven at gcc dot gnu dot org
2006-07-22 2:01 ` kargl at gcc dot gnu dot org
2006-07-22 17:55 ` kargl at gcc dot gnu dot org
2006-07-22 17:58 ` [Bug fortran/28439] [4.1 only] " kargl at gcc dot gnu dot org
2006-07-24 16:54 ` kargl at gcc dot gnu dot org
2006-07-25 23:31 ` kargl at gcc dot gnu dot org
2006-07-25 23:32 ` kargl at gcc dot gnu dot org
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).