- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I'm having a hard time understanding what is wrong with the following code that slices an array by property of derived type and I'm suspecting a compiler bug :
[fortran]module crash
type foo
integer :: i
end type foo
type bar
type(foo) :: foos(5)
end type bar
contains
subroutine print_foos(arg)
type(foo), intent(in) :: arg(:)
call print_int(arg%i)
end subroutine print_foossubroutine print_int(arg)
integer, intent(in) :: arg(:)
integer :: i
do i=lbound(arg, 1), ubound(arg, 1)
print '(I)', arg(i)
end do
end subroutine print_intend module crash
program crash_test
use :: crash
type(bar) :: a
do i=lbound(a%foos, 1), ubound(a%foos, 1)
a%foos(i)%i = i
end docall print_int(a%foos%i) ! OK
call print_foos(a%foos) ! KOend program crash_test[/fortran]
The call to print_int correctly prints 1, 2, 3, 4, 5 while print_foos prints unitialized values (zeros). Am I doing anything non standard ? Note that the compiler does not complain nor ICE but gives IMHO wrong results.
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 13.1.1.171 Build 20130313
Thank you for you help.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The same code compiled with gfortran 4.7.2 runs fine, so its seems to be an Intel fortran bug. Could anyone confirm this ?
I should have say "component" rather than "property" in the title, sorry about that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Steve, thank you for your investigation. It's a pattern that I use surprisingly often in my code... My current workaround is to make a local copy of the data in the intermediate function (print_foos in my example code). If someone has a better one, I'd appreciate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have escalated this as issue DPD200243231. I observed a few things. 1) This worked in 12.1.5 but broke in 13.0.0. 2) It seems to work fine when built for x64 (not IA-32). 3) It works if the dummy argument to print_int is not an assumed-shape array, but that's not a reasonable workaround.
Here is a more reasonable workaround that doesn't involve making a copy. Add an intermediate routine that takes an adjustable array, like this:
[fortran]
subroutine print_foos(arg)
type(foo), intent(in) :: arg(:)
call print_ints(arg%i, size(arg))
end subroutine print_foos
subroutine print_ints(arg, n)
integer, intent(in) :: n, arg(n)
call print_int(arg)
end subroutine print_ints
[/fortran]
Lastly, in passing, I'll note that your lbound call will always return 1, no matter how the actual argument was declared in the caller. This is the way the language defines it with assumed-shape dummy arguments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have fixed this for a release later this year.

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