- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider the following program:
[fortran]
module io_mod
implicit none
contains
subroutine read_vals_assumed_shape(vals, ios)
character(*), intent(inout), contiguous :: vals(:)
integer, intent(out) :: ios
read(1, pos = 1, iostat = ios) vals
end subroutine
subroutine read_vals_assumed_size(vals, size_vals, ios)
character(*), intent(inout) :: vals(*)
integer, intent(in) :: size_vals
integer, intent(out) :: ios
read(1, pos = 1, iostat = ios) vals(:size_vals)
end subroutine
end module
program Console24
use io_mod
implicit none
character(64), allocatable :: vals(:)
integer :: ios
allocate (vals(300000))
vals = ' '
open(1, file = 'test.out', access='stream', form = 'unformatted')
write(1, pos = 1, iostat = ios) vals
close(1)
open(1, file = 'test.out', access='stream', form = 'unformatted')
! The following three statements should do the same thing
read(1, pos = 1, iostat = ios) vals
call read_vals_assumed_size(vals, size(vals), ios)
call read_vals_assumed_shape(vals, ios)
close(1)
end program Console24
[/fortran]
This crashes on line 8 with a stack overflow in recent releases of the compiler (I've tried this with XE 2013 update 1 and XE 2013 SP1 update 1).
Workarounds:
1) Use the "/heap_arrays:0" option.
2) Use an assumed size argument.
3) Read the array in stack friendly chunks.
Or should the compiler be able to cope with this as is, given the contiguous attribute on vals (which seems to make no difference in this case)?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree with you that the stack temporary should not have been created. especially as you added the CONTIGUOUS attribute. I will ask the developers to improve this. Issue ID is DPD200249510.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve,
Aside: the forum syntax highlighting strips out blank lines, so the stack overflow is on line 7 of the posted listing (read(1, pos = 1, iostat = ios) vals) in io_mod::read_vals_assumed_shape.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah, I figured that out...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For a release later this year, we've fixed the compiler to use the CONTIGUOUS attribute to avoid creating stack temps.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page