https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84615

--- Comment #9 from Janne Blomqvist <jb at gcc dot gnu.org> ---
(In reply to Dominique d'Humieres from comment #8)
> Another test that does not require -fdefault-integer-8
> 
> module chtest
> contains
>   function chararray2string(chararray) result(text)
>     character(len=1), dimension(:) :: chararray    ! input
>     character(len=int(size(chararray, 1), kind=8)) :: text      ! output
>     print *, ">", chararray, "<"
>     do i = 1,size(chararray,1)
>       text(i:i) = chararray (i)
>     end do
>     print *, ">", text, "<"
>   end function chararray2string
> end module chtest
> program TestStringTools
>   use chtest
>   character(len=52)               :: txt
>   character(len=1), dimension(52) :: chararr = &
>         (/(char(i+64),char(i+96), i = 1,26)/)
>   print *, ">", chararr, "<"
>   txt = chararray2string(chararr)
>   if (txt .ne. "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz") &
>         STOP 1
> end program TestStringTools

I think I see what the problem is, though I don't yet know how to fix it.
Looking at the tree-dump-original (compiled on i686) we have the function
chararray2string:

chararray2string (character(kind=1)[1:..__result] & __result, integer(kind=4)
.__result, ...

i.e. the charlen type is integer(4) (gfc_charlen_type_node in the frontend) as
it should be, although in the source the length is declared as an integer(8).
This is the correct thing to do, as we cannot know what the charlen kind of a
function is. Thus we must always, regardless of how it's declared, convert it
to gfc_charlen_type_node.

However, when looking at how that function is called, it uses an integer(8)
variable for the charlen. This is clearly wrong. Looking at the .mod file we
have

(2 'chararray2string' 'chtest' '' 1 ((PROCEDURE UNKNOWN-INTENT
MODULE-PROC DECL UNKNOWN 0 0 FUNCTION ALWAYS_EXPLICIT) () (CHARACTER 1 0
0 0 CHARACTER ((FUNCTION (INTEGER 8 0 0 0 INTEGER ()) 0 3 (('' (
FUNCTION (INTEGER 4 0 0 0 INTEGER ()) 0 4 (('' (VARIABLE (CHARACTER 1 0
0 0 CHARACTER ((CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 '1' ()))) 1 5 (
(ARRAY (FULL 1 2))) ())) ('' (CONSTANT (INTEGER 4 0 0 0 INTEGER ()) 0 '1'
())) ('' ())) '' 0 'size' ())) ('kind' (CONSTANT (INTEGER 4 0 0 0
INTEGER ()) 0 '8' ()))) '__int_8_i4' 0 'int' ()))) 6 0 (5) () 7 () () ()
0 0)


That is, if I'm reading this correctly, the type of the charlen of the return
value is "FUNCTION (INTEGER 8...".  


I suspect this is the same reason for all those regressions with
"-fdefault-integer-8 -m32".

Reply via email to