Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Crash with allocatable character variable that is declared with a fixed length

$
0
0

The following small program compiles without warnings or errors:

program test
    call s1('abc')

    contains
    subroutine s1(s)
        character(len=*), intent(in) :: s
        character(len=20), allocatable :: c
        c = s
        print *, c
    end subroutine
end program

But when executed it crashes, with more or less explicit messages depending on the compile options:

C:\TEMP>ifort test.f90 /debug:full /dbglibs
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.110 Build 20150815
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:test.exe
-debug
-pdb:test.pdb
-subsystem:console
test.obj

C:\TEMP>test
forrtl: severe (157): Program Exception - access violation
Image              PC                Routine            Line        Source
test.exe           00007FF66202806B  Unknown               Unknown  Unknown
test.exe           00007FF661FA1E62  Unknown               Unknown  Unknown
test.exe           00007FF661FA10C7  Unknown               Unknown  Unknown
test.exe           00007FF661FA103D  Unknown               Unknown  Unknown
test.exe           00007FF66208D02E  Unknown               Unknown  Unknown
test.exe           00007FF662026DEC  Unknown               Unknown  Unknown
test.exe           00007FF662026F2E  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFB64E016AD  Unknown               Unknown  Unknown
ntdll.dll          00007FFB668D34A5  Unknown               Unknown  Unknown

C:\TEMP>

adding /stand:f08 doesn't flag any warnings either.

I do think this is related to the fact that the character variable c is declared with a length and as allocatable, which must confuse the runtime.
I can not find something in the standard that would forbid this, but I can not see how it could be useful either. I stumbled across it when I changed some character variables from fixed size to allocatable and forgot to change the length to ":"

 

 


Viewing all articles
Browse latest Browse all 5691

Trending Articles