Deferred length string component: segmentation fault

Deferred length string component: segmentation fault

In a project I am working on, I changed a fixed length string in a structure within a module to a deferred length string and the result was an internal compiler error (the code compiled and ran without issue before the change).  I cannot reproduce the internal compiler error with a simple case, but I do get a segmentation fault in the below program when it hits the WRITE() statement.  It is unclear to me what the issue is or if this is even related to the internal compiler error I was trying to reproduce.  When compiling with '-std03', I get "warning #5436: Overlapping storage initializations encountered with S", so maybe it has something to do with the initialization, though I do not see multiple initializations here.

Fortran compiler version is Version (64-bit), on Ubuntu 14.04 (beta).

The code is also attached:

MODULE stringmod
  TYPE(A), SAVE :: S = A('_test__TEST_')
  SUBROUTINE TestPrint()
    WRITE(*,*) S%string

PROGRAM stringtest
  USE stringmod
  CALL TestPrint()


Downloadapplication/octet-stream StringTest.f90287 bytes
4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

If I may make one observation; it is not legal in a constant expression to initialize an allocatable component to anything other than a NULL().

Unfortunately, we did not diagnose that in 14.0.2, although that has been changed for a release coming later this year, resulting in this error:

stringtest.f90(5): error #6273: In a constant expression, the only value that may correspond to an allocatable component is a reference to NULL().   ['_test__TEST_']
  TYPE(A), SAVE :: S = A('_test__TEST_')
compilation aborted for stringtest.f90 (code 1)

So, this means that in your code, when TestPrint is called, S%String has not been allocated, and you see the run-time error reported.

               Does this help?



Glad to read the issue in Intel Fortran will be fixed in a release later this year.  FWIW, gfortran 4.9 gives the following error:

gfortran.exe -JDebug\GNU\ -Wall -fall-intrinsics -g -std=f2008
-c C:\dev\Fortran\Test18\sor\TestFor.f90 -o Debug\GNU\sor\TestFor.o
  TYPE(A), SAVE :: S = A('_test__TEST_')
Error: Invalid initialization expression for ALLOCATABLE component 'string' in structure
constructor at (1)

You may wish to check whether the new Intel Fortran version would give a message as clear-cut or a text that is even more informative for the developer.


Thank you Lori.

Now that you mention it, I do recall trying to initialize allocatable components this way once before (years ago and not with deferred length strings), but compiler errors showed me the error of my ways.  I seem to have forgotten in the years since and the lack of a compiler check failed to remind me.  I am glad to hear the check will occur in future releases.

It sounds like this might be the source of the internal compiler error in my original project as I am attempting to do the same there.

Leave a Comment

Please sign in to add a comment. Not a member? Join today