Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29230 Discussions

Bad codegen for automatic reallocated arrays results in stack overflow

tobias-loew
New Contributor I
1,704 Views

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 Replies
Ron_Green
Moderator
1,443 Views

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. 

0 Kudos
tobias-loew
New Contributor I
1,328 Views

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
Moderator
1,045 Views

BugID is CMPLRLLVM-69147


0 Kudos
Reply