Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29233 Discussões

Bad codegen for automatic reallocated arrays results in stack overflow

tobias-loew
Novo colaborador I
1.707 Visualizações

The following code generates a stack overflow on Windows (for a standard 1MB stack) even when compiled with default "Release" settings.

 

    module test
    
    contains
    subroutine add_lines()
    character(500):: line
    integer:: loop_file
    character(500),dimension(:),allocatable:: c

    allocate(c(0))
    c = ''

    do loop_file=1,10000
        line = 'abcd'
        c = [character(len=500) :: c , line]
    end do

    end subroutine
    end module test

    
    program Console1
    use test
    implicit none

    
    call add_lines()

    end program Console1
    

 

0 Kudos
3 Respostas
Ron_Green
Moderador
1.446 Visualizações

This example is curious.  I also see the stack exhaustion.  I can prevent it by adding -heap-arrays.  But it still should not need this option.

 

I need to investigate this more.  it's not obvious to me why the constructor would blow up stack.  It should only use 500 chars of storage.  Might be that the RHS constructor is not being freed up after the copy to the LHS.  Just a suspicion. 

tobias-loew
Novo colaborador I
1.331 Visualizações

Yes, I also just found out that -heap-arrays (even with sizes far greater than the stack size) prevents it.

But without -heap-arrays:

While debugging through the loop, the stack-pointer is growing all the time. After leaving "add_lines" the stack-pointer has the correct value again (when the loop-counter is below the stack-overflow limit, of course).

Ron_Green
Moderador
1.048 Visualizações

BugID is CMPLRLLVM-69147


Responder