* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
@ 2013-12-19 11:31 ` dominiq at lps dot ens.fr
2015-08-18 8:15 ` fxcoudert at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-12-19 11:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
Dominique d'Humieres <dominiq at lps dot ens.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-12-19
Ever confirmed|0 |1
--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed at r206105. Using result(res) as in
module m1
implicit none
integer, parameter :: dp = kind([double precision::])
contains
recursive function f(x) result(res)
integer, intent(in) :: x
real(dp) res(x/2)
integer y(size(res)+1)
if (x==1) return
write(*,*) 'size(f) = ',size(res)
write(*,*) 'size(y) = ',size(y)
res = f(x/2)
end function f
end module m1
program bug3
use m1
implicit none
real y
y = sum(f(8))
print *, y
end program bug3
make the code working:
size(f) = 4
size(y) = 5
size(f) = 2
size(y) = 3
size(f) = 1
size(y) = 2
0.00000000
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
2013-12-19 11:31 ` [Bug fortran/59104] " dominiq at lps dot ens.fr
@ 2015-08-18 8:15 ` fxcoudert at gcc dot gnu.org
2022-01-24 21:57 ` anlauf at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2015-08-18 8:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2013-12-19 00:00:00 |2015-8-18
CC| |fxcoudert at gcc dot gnu.org
Blocks| |32834
--- Comment #2 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
F95 bug. Still present. In the generated code, the size of Y is computed before
the bounds for the F result are set, which leads to the error.
Slightly reduced testcase:
$ cat a.f90
program bug3
real y(2)
y = f(2)
print *, y
contains
function f(x)
integer x
real f(x)
integer y(size(f))
write(*,*) 'size(f) = ',size(f)
write(*,*) 'size(y) = ',size(y)
f = -42
end function f
end program bug3
$ gfortran a.f90 -std=f95 && ./a.out
size(f) = 2
size(y) = 0
-42.0000000 -42.0000000
Slight modification of the source leads to an ICE on what I think is invalid
code:
$ cat a.f90
function f(x)
integer x
integer y(size(f))
real f(x)
write(*,*) 'size(f) = ',size(f)
write(*,*) 'size(y) = ',size(y)
f = -42
end function f
$ gfortran a.f90 -std=f95 && ./a.out
a.f90:3:0:
integer y(size(f))
1
internal compiler error: in gfc_conv_expr_descriptor, at
fortran/trans-array.c:6534
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32834
[Bug 32834] [Meta-bug] 'Fortran 95'-only failures
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
2013-12-19 11:31 ` [Bug fortran/59104] " dominiq at lps dot ens.fr
2015-08-18 8:15 ` fxcoudert at gcc dot gnu.org
@ 2022-01-24 21:57 ` anlauf at gcc dot gnu.org
2024-05-22 7:46 ` pault at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-24 21:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
Last reconfirmed|2015-08-18 00:00:00 |2022-1-24
--- Comment #3 from anlauf at gcc dot gnu.org ---
Interestingly, when using the RESULT clause in the function declaration,
the evaluation of SIZE appears to work for:
program bug
implicit none
real :: u(3)
u = f(3)
u = g(3)
contains
!-
function f(n)
integer, intent(in) :: n
real :: f(n)
integer :: y(size(f))
f = 1
print *, 'f: size(y) =',size(y)
end function f
!-
function g(n) result (f)
integer, intent(in) :: n
real :: f(n)
integer :: y(size(f))
f = 2
print *, 'g: size(y) =',size(y)
end function g
end
This prints:
f: size(y) = 0
g: size(y) = 3
(Expecting size=3 in both cases).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
` (2 preceding siblings ...)
2022-01-24 21:57 ` anlauf at gcc dot gnu.org
@ 2024-05-22 7:46 ` pault at gcc dot gnu.org
2024-05-23 5:30 ` pault at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu.org @ 2024-05-22 7:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pault at gcc dot gnu.org
--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
The problem lies in gfc_conv_expr_descriptor, as the following demonstrates:
module m1
implicit none
integer, parameter :: dp = kind([double precision::])
contains
function f(x)
integer, intent(in) :: x
real(dp) f(x/2)
integer y(size(f)+1)
write(*,*) 'size(f) = ',size(f)
write(*,*) 'size(y) = ',my_size(y)
f = 0
end function f
integer function my_size (arg)
integer :: arg(:)
my_size = size(arg)
end
end module m1
program bug3
use m1
implicit none
real y
y = sum(f(2))
end program bug3
In both this and the original testcase, the result depends ultimately on a
'ubound.x' that has not been set.
I am not sure that I understand why explicit shape arrays are being handled
this way in size, when all the information needed is present in the array_spec.
However, the passing of an incorrect descriptor to 'my_size' has to be fixed.
Cheers
Paul
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
` (3 preceding siblings ...)
2024-05-22 7:46 ` pault at gcc dot gnu.org
@ 2024-05-23 5:30 ` pault at gcc dot gnu.org
2024-06-04 21:51 ` pault at gcc dot gnu.org
2024-06-20 7:01 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu.org @ 2024-05-23 5:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 58275
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58275&action=edit
"Fix" for this PR
This patch causes regressions in dependent_decls_1.f90 and mapping_[1,2].f90.
However, it demonstrates that the cause of this PR is that the symbols arriving
in gfc_trans_deferred_vars must be treated in an order that respects
dependencies or, perhaps better, declaration order.
Paul
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
` (4 preceding siblings ...)
2024-05-23 5:30 ` pault at gcc dot gnu.org
@ 2024-06-04 21:51 ` pault at gcc dot gnu.org
2024-06-20 7:01 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pault at gcc dot gnu.org @ 2024-06-04 21:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org
--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 58348
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58348&action=edit
Fix for this PR
This works and even regtests. I will include character lengths before
submitting.
The eventual testcase is rather more elaborate but the version below gives an
idea of what is now fixed,
Paul
module m1
implicit none
integer, parameter :: dp = kind([double precision::])
contains
function f(x)
integer, intent(in) :: x
real(dp) f(x/2)
real(dp) g(x/2)
! block
integer y(size(f)+1)
integer z(size(f) + size(y)) ! This caused all manner of trouble.
f = 10.0
y = 1
z = 1
write(*,*) 'size(f) = ', size(f), f
write(*,*) 'size(y) = ', size(y), y
write(*,*) 'size(z) = ', size(z), z
! end block
end function f
function e(x) result(f)
integer, intent(in) :: x
real(dp) f(x/2)
real(dp) g(x/2)
integer y(size(f)+1)
integer z(size(f) + size(y)) ! As did this.
f = 10.0
y = 1
z = 1
write(*,*) 'size(f) = ', size(f), f
write(*,*) 'size(y) = ', size(y), y
write(*,*) 'size(z) = ', size(z), z
end function e
end module m1
program bug3
use m1
implicit none
real(dp) y
y = sum(f(2))
print *, y
y = sum(e(4))
print *, y
end program bug3
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/59104] Wrong result with SIZE specification expression
2013-11-13 7:33 [Bug fortran/59104] New: Wrong result with SIZE specification expression burnus at gcc dot gnu.org
` (5 preceding siblings ...)
2024-06-04 21:51 ` pault at gcc dot gnu.org
@ 2024-06-20 7:01 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-20 7:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59104
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:
https://gcc.gnu.org/g:ccaa39a268bef2a1d8880022696ff2dcaa6af941
commit r15-1468-gccaa39a268bef2a1d8880022696ff2dcaa6af941
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Thu Jun 20 08:01:36 2024 +0100
Fortran: Auto array allocation with function dependencies [PR59104]
2024-06-20 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/59104
* dependency.cc (dependency_fcn, gfc_function_dependency): New
functions to detect dependency in array bounds and character
lengths on old style function results.
* dependency.h : Add prototype for gfc_function_dependency.
* error.cc (error_print): Remove trailing space.
* gfortran.h : Remove dummy_order and add fn_result_spec.
* symbol.cc : Remove declaration of next_dummy_order..
(gfc_set_sym_referenced): remove setting of symbol dummy order.
* trans-array.cc (gfc_trans_auto_array_allocation): Detect
non-dummy symbols with function dependencies and put the
allocation at the end of the initialization code.
* trans-decl.cc : Include dependency.h.
(decl_order): New function that determines uses the location
field of the symbol 'declared_at' to determine the order of two
declarations.
(gfc_defer_symbol_init): Call gfc_function_dependency to put
dependent symbols in the right part of the tlink chain. Use
the location field of the symbol declared_at to determine the
order of declarations.
(gfc_trans_auto_character_variable): Put character length
initialization of dependent symbols at the end of the chain.
* trans.cc (gfc_add_init_cleanup): Add boolean argument with
default false that determines whther an expression is placed at
the back or the front of the initialization chain.
* trans.h : Update the prototype for gfc_add_init_cleanup.
gcc/testsuite/
PR fortran/59104
* gfortran.dg/dependent_decls_2.f90: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread