[Patch, fortran] PR24311 - MERGE with character arguments causing ICE in IO statements.

Paul Thomas paulthomas2@wanadoo.fr
Wed Oct 12 17:12:00 GMT 2005


Tobi,

>>+   /* Merge is unusual in that tsource can be a character constant, whose typespec
>>+      is transferred to that of the output array.  This will not have had a charlen
>>+      created, so it is done here to prevent the middle-end being hit by an
>>+      apparently incomplete character array(PR24311).  */
>>
>
>Wouldn't this be true for all other array transformational functions as well?
>
Looking through all the array intrinsics, it turns out that the answer 
is yes.  SPREAD is the only other array construction/manipulation 
function that can take a scalar source and it is doubly broken:

This works:
  character*1  :: c(1) = "a"
  print *, spread (c, 1 , 10)
  end

but these segfault:
  character*1  :: c = "a"
  print *, spread (c, 1 , 10)       ! at runtime (for any type)
  end

  print *, spread ("a", 1 , 10)     ! during compilation for characters
  end

The latter is corrected by the the same fix as for merge.

Note that scalar sources are specified in the standard and work fine 
with other brands.

I propose to recast scalar sources as rank 1 arrays with one element in 
gfc_resolve_spread, since the result shape is determined in there.  This 
results in an unambiguous package for the library, even if a bit of 
joggling with shapes might be necessary there too.

Paul T





More information about the Fortran mailing list