Created attachment 27360 [details] source raising the segfault Executing the binary compiled from attached source prints: size 78 arr: ABCDEGHIJ size 1 Speicherzugriffsfehler (Speicherabzug geschrieben) Besides the segfault, the array size should not change. This is not reproducable when replacing the character(*)-type entities by integer(INT64) nor when omitting the function call in the constructor.
It also doesn't segfault if one replaces the call by: call rou( [character(len=120) :: "123",uCase("abcde"),uCase("ghij")]) Namely: adding as first item in the constructor list a string literal (which by construction has a known length). According to VALGRIND, the problem is an Invalid free() / delete / delete[] / realloc() in line 10 or, if commented, in line 9. Line 9 is the "call rou" line. With ifort 12.1, the programs seems to work while with cryftn it fails at run time with an illegal instruction. In any case, the program looks valid to me.
Simplified program. * As is, it prints 128 * Without "txt", it prints 5 and segfaults * Without character(len=128) :: "txt", it prints 5 and works Thus, the extension to 128 characters does not properly work in the case of having no character literal. That matches what is in the code: character(kind=1) A.16[2][1:5]; vs. character(kind=1) A.15[3][1:128]; I have not looked through the source code, but the first place, where constructors string lengths are handled is array.c's gfc_resolve_character_array_constructor. I don't quickly see whether it does so correctly or not. If it does, the failure must be later. It might be that in that function, the "txt" is correctly extended and padded to len=128 - and that then everything is later handled correctly because the first element has the right size? program charArrErr implicit none call rou([character(len=128) :: "txt", uCase("abcde"),uCase("ghij_")]) contains subroutine rou(arr) implicit none character(*),intent(in) :: arr(:) print *, len(arr) end subroutine function uCase(str) implicit none character(*), intent(in) :: str character(len(str)) :: uCase uCase=str end function uCase end program charArrErr
Still present at revision 200133.
This seems to have morphed into a strange off-by-1 in the array constructor. Consider this code, program chararrerr implicit none character(len=128) :: str(2) str = [ucase("abcde"), ucase("ghij")] contains function ucase(str) character(*) :: str character(len(str)) :: ucase intent(in) :: str ucase = str print *, '>' // trim(str) // '<', len(str) end function ucase end program chararrerr Trunk gives % gfcx -o z a.f90 -fdump-tree-original && ./z >abcde< 5 >abcde< 5 >ghij< 4 For some reason, the first element is evaluated twice.