public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/15273] New: Wrong output from a pure subroutine
@ 2004-05-04 1:56 tcc at sentex dot net
2004-05-04 2:25 ` [Bug fortran/15273] [gfortran] " pinskia at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: tcc at sentex dot net @ 2004-05-04 1:56 UTC (permalink / raw)
To: gcc-bugs
The code below gives wrong output, but is ok if "pure" is dropped.
program testp
integer, parameter :: intp = 3
integer :: j
call subx(intp,j)
print *, intp, j
contains
pure subroutine subx(i,iout)
integer, intent(in) :: i
integer, intent(out) :: iout
iout = i + 1
end subroutine subx
end program testpar
$ gfortran -o testp testp.f90
$ ./testp
3 1073873990
$
--
Summary: Wrong output from a pure subroutine
Product: gcc
Version: tree-ssa
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tcc at sentex dot net
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
@ 2004-05-04 2:25 ` pinskia at gcc dot gnu dot org
2004-05-04 13:30 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-04 2:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-04 02:25 -------
I think the issue is that the function is not really pure in the GCC sense.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2004-05-04 02:25:02
date| |
Summary|Wrong output from a pure |[gfortran] Wrong output from
|subroutine |a pure subroutine
Target Milestone|--- |tree-ssa
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
2004-05-04 2:25 ` [Bug fortran/15273] [gfortran] " pinskia at gcc dot gnu dot org
@ 2004-05-04 13:30 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 13:31 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Tobias dot Schlueter at physik dot uni-muenchen dot de @ 2004-05-04 13:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de 2004-05-04 13:30 -------
(In reply to comment #0)
> The code below gives wrong output, but is ok if "pure" is dropped.
That code should not compile.
> pure subroutine subx(i,iout)
> integer, intent(in) :: i
> integer, intent(out) :: iout
the first Constraint from 12.6. in the (draft) standard reads:
---
The /specification-part/ of a pure subroutine subprogram shall specify that all
dummy arguments have INTENT(IN) except procedure arguments and arguments with
the POINTER attribute.
---
This is violated here.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
2004-05-04 2:25 ` [Bug fortran/15273] [gfortran] " pinskia at gcc dot gnu dot org
2004-05-04 13:30 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
@ 2004-05-04 13:31 ` pinskia at gcc dot gnu dot org
2004-05-04 13:44 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-04 13:31 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-04 13:31 -------
That is what I thought, it is invalid code so marking as such.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords|wrong-code |accepts-invalid
Last reconfirmed|2004-05-04 02:25:02 |2004-05-04 13:31:48
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (2 preceding siblings ...)
2004-05-04 13:31 ` pinskia at gcc dot gnu dot org
@ 2004-05-04 13:44 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 13:46 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Tobias dot Schlueter at physik dot uni-muenchen dot de @ 2004-05-04 13:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de 2004-05-04 13:44 -------
It's quite interesting to see how this problem comes to happen:
I used this slightly revised test program:
[tobi@marktplatz tests]$ cat pr15273.f90
program testp
integer, parameter :: intp = 3
integer :: j
call subx(intp,j)
print *, intp, j
call suby(intp,j)
print *, intp, j
contains
pure subroutine subx(i,iout)
integer, intent(in) :: i
integer, intent(out) :: iout
iout = i + 1
end subroutine subx
subroutine suby(i,iout)
integer, intent(in) :: i
integer, intent(out) :: iout
iout = i + 1
end subroutine suby
end program testp
compiling with "gfortran pr15273.f90 -fdump-tree-all" yields these dumps:
[tobi@marktplatz tests]$ cat pr15273.f90.t03.original
suby (i, iout)
{
*iout = *i + 1;
subx (i, iout)
{
*iout = *i + 1;
MAIN__ ()
{
int4 j;
static subx;
static suby;
{
int4 T.4;
T.4 = 3;
subx (&T.4, &j);;
}
_gfortran_filename = "pr15273.f90";
_gfortran_line = 5;
_gfortran_ioparm.unit = 6;
_gfortran_ioparm.list_format = 1;
_gfortran_st_write ();
{
int4 T.5;
T.5 = 3;
_gfortran_transfer_integer (&T.5, 4);;
}
_gfortran_transfer_integer (&j, 4);
_gfortran_st_write_done ();
{
int4 T.6;
T.6 = 3;
suby (&T.6, &j);;
}
_gfortran_filename = "pr15273.f90";
_gfortran_line = 7;
_gfortran_ioparm.unit = 6;
_gfortran_ioparm.list_format = 1;
_gfortran_st_write ();
{
int4 T.7;
T.7 = 3;
_gfortran_transfer_integer (&T.7, 4);;
}
_gfortran_transfer_integer (&j, 4);
_gfortran_st_write_done ();;
}
[tobi@marktplatz tests]$ cat pr15273.f90.t13.lower
;; Function subx (subx.1)
subx (i, iout)
{
int4 T.3;
int4 T.2;
T.2 = *i;
T.3 = T.2 + 1;
*iout = T.3;
}
;; Function suby (suby.0)
suby (i, iout)
{
int4 T.1;
int4 T.0;
T.0 = *i;
T.1 = T.0 + 1;
*iout = T.1;
}
;; Function MAIN__ (MAIN__)
MAIN__ ()
{
int4 T.7;
int4 T.6;
int4 T.5;
int4 T.4;
int4 j;
T.4 = 3;
_gfortran_filename = "pr15273.f90";
_gfortran_line = 5;
_gfortran_ioparm.unit = 6;
_gfortran_ioparm.list_format = 1;
_gfortran_st_write ();
T.5 = 3;
_gfortran_transfer_integer (&T.5, 4);
_gfortran_transfer_integer (&j, 4);
_gfortran_st_write_done ();
T.6 = 3;
suby (&T.6, &j);
_gfortran_filename = "pr15273.f90";
_gfortran_line = 7;
_gfortran_ioparm.unit = 6;
_gfortran_ioparm.list_format = 1;
_gfortran_st_write ();
T.7 = 3;
_gfortran_transfer_integer (&T.7, 4);
_gfortran_transfer_integer (&j, 4);
_gfortran_st_write_done ();
}
the interesting part is that in the lowered tree, the call to the pure
subroutine has disappeared. That's why j is uninitialized. Now I don't know if
that's a legal transformation, but I think it is.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (3 preceding siblings ...)
2004-05-04 13:44 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
@ 2004-05-04 13:46 ` pinskia at gcc dot gnu dot org
2004-05-04 14:00 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-04 13:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-04 13:46 -------
It is legal because the return value for subx is ignored since subx is pure the call can be removed.
--
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2004-05-04 13:31:48 |2004-05-04 13:46:14
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (4 preceding siblings ...)
2004-05-04 13:46 ` pinskia at gcc dot gnu dot org
@ 2004-05-04 14:00 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 14:03 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Tobias dot Schlueter at physik dot uni-muenchen dot de @ 2004-05-04 14:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de 2004-05-04 14:00 -------
Sorry, it looks like I switched paragraphs in the middle of reading the
standard. The code is LEGAL.
The first two constraints read correctly:
----
The /specification-part/ of a pure *function* subprogram shall specify that all
dummy arguments have INTENT(IN) except procedure arguments and arguments with
the POINTER attribute.
----
and
----
The /specification-part/ of a pure *subroutine* subprogram shall specify the
intents of all dummy arguments except procedure arguments, alternate return
indicators, and arguments with the POINTER attribute.
----
Come to think about it , this makes sense, as otherwise a pure subroutine
couldn't be very meaningful (and optimized away at will, as in this example).
For the curious, note 12.34 gives some insight into the logic behind this.
So it looks like the actual bug is that the middle-end is overly effective in
eliminating calls to pure functions.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (5 preceding siblings ...)
2004-05-04 14:00 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
@ 2004-05-04 14:03 ` pinskia at gcc dot gnu dot org
2004-05-04 19:53 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-23 9:42 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-04 14:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-04 14:03 -------
The real issue is the front-end is marking this function call as pure in the sense if the return value is
ignored then it can be removed so the bug is in the front-end marking it as pure when it is not really
that kind of pure.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords|accepts-invalid |wrong-code
Last reconfirmed|2004-05-04 13:46:14 |2004-05-04 14:03:51
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (6 preceding siblings ...)
2004-05-04 14:03 ` pinskia at gcc dot gnu dot org
@ 2004-05-04 19:53 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-23 9:42 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: Tobias dot Schlueter at physik dot uni-muenchen dot de @ 2004-05-04 19:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de 2004-05-04 19:53 -------
Patch here: http://gcc.gnu.org/ml/gcc-patches/2004-05/msg00195.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/15273] [gfortran] Wrong output from a pure subroutine
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
` (7 preceding siblings ...)
2004-05-04 19:53 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
@ 2004-05-23 9:42 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-23 9:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-22 14:27 -------
Fixed.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15273
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-05-22 14:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-04 1:56 [Bug fortran/15273] New: Wrong output from a pure subroutine tcc at sentex dot net
2004-05-04 2:25 ` [Bug fortran/15273] [gfortran] " pinskia at gcc dot gnu dot org
2004-05-04 13:30 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 13:31 ` pinskia at gcc dot gnu dot org
2004-05-04 13:44 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 13:46 ` pinskia at gcc dot gnu dot org
2004-05-04 14:00 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-04 14:03 ` pinskia at gcc dot gnu dot org
2004-05-04 19:53 ` Tobias dot Schlueter at physik dot uni-muenchen dot de
2004-05-23 9:42 ` pinskia 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).