Topic: 32 bit executable fails, 64 bit fine

This may be a gcc/gfortran library bug, but might be something related to your build of gfortran.  The program below crashes with

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0  ffffffff

when building with 32 bit architecture selected (-m32 flag), but executes correctly without error when 64 bit is selected.

program defer
  implicit none
  character(len=:), dimension(:), allocatable::s
  s=["a12","ab3","abc"]
  write(*,*)"shape of s: ",shape(s)
end program defer

Re: 32 bit executable fails, 64 bit fine

You're probably seeing the crash because you're assigning values to s, an allocatable array, without first allocating it.  If you were to allocate first, it should work on both:

program defer
  implicit none
  character(len=:), dimension(:), allocatable::s

  allocate(character(len=3)::s(3))

  s(1) = "a12"
  s(2) = "ab3"
  s(3) = "abc"
  write(*,*)"shape of s: ",shape(s)
end program defer

The fact that it works on 64-bit is incidental.  In reality, you're overwriting an undefined area of memory and luckily getting away with it.

Jeff Armstrong
Approximatrix, LLC

3 (edited by baf1 2016-03-12 22:23:24)

Re: 32 bit executable fails, 64 bit fine

Jeff

No, I do not believe you are correct.  Starting with Fortran 2003, allocate on assign is allowed.  However, I will check further on this.

Re: 32 bit executable fails, 64 bit fine

Other programmers and the Intel compiler agree with me that the code is standards conforming.  Likely a gfortran bug, although odd that it only occurs with the 32bit executable.  I am assuming you build gcc/gfortran all at once from the same source.  I filed a gfortran bug report on bugzilla.

Re: 32 bit executable fails, 64 bit fine

Jeff

The gfortran developers confirm that this is a bug in gfortran which they believe (hope) has been fixed in a very recent set of patches submitted to both the 6.0 branch and backported to the 5-branch.  Perhaps you will have a chance in the not-to-distant future to rebuild gfortran from the most recent 5.3.1 sources.

Re: 32 bit executable fails, 64 bit fine

baf1 wrote:

Starting with Fortran 2003, allocate on assign is allowed.

Ah, I wasn't aware of that addition to the standard.  I can't say that I agree with it, though, but the Fortran standards committee always seems to make odd decisions.

If it is being backported to 5.3, it will be integrated when/if 5.3.1 is released.  We have a policy of only shipping release versions of GNU Fortran. Thank you for seeing that the bug is fixed, though!

Jeff Armstrong
Approximatrix, LLC

Re: 32 bit executable fails, 64 bit fine

jeff wrote:
baf1 wrote:

Starting with Fortran 2003, allocate on assign is allowed.


If it is being backported to 5.3, it will be integrated when/if 5.3.1 is released.  We have a policy of only shipping release versions of GNU Fortran. Thank you for seeing that the bug is fixed, though!


OK, that likely means waiting until 6.1 is released in a few months.