This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/82995] New: Segmentation fault passing optional argument to intrinsic sum function


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82995

            Bug ID: 82995
           Summary: Segmentation fault passing optional argument to
                    intrinsic sum function
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: werner.blokbuster at gmail dot com
  Target Milestone: ---

With gfortran 7.2 on linux the following code gives a segmentation fault on the
output line starting "C2". Some earlier versions (before 4.9) give the answer
'0' instead.

module y 
    implicit none 
contains 
    function test_sum(input,mask) 
        integer, intent(in) :: input(:) 
        logical, intent(in), optional :: mask(:) 
        integer :: test_sum 
            if(present(mask)) then 
                test_sum = sum(input,mask) 
            else 
                test_sum = sum(input) 
            endif 
    end function test_sum 

    function my_sum(input,mask) 
        integer, intent(in) :: input(:) 
        logical, intent(in), optional :: mask(:) 
        integer :: my_sum 
            my_sum = sum(input,mask) 
    end function my_sum 
end module y 

program test_my_sum 
    use y, only:  my_sum, test_sum 
    implicit none 
    integer :: input(3) = [1,2,3] 
    logical :: mask(3) = [.true.,.false.,.true.] 

        ! This works: 

        write(*,*) 'A1: ', sum(input) 
        write(*,*) 'A2: ', sum(input,mask) 

        ! This works: 

        write(*,*) 'B1: ', test_sum(input) 
        write(*,*) 'B2: ', test_sum(input,mask) 

        ! This works: 

        write(*,*) 'C1: ', my_sum(input,[.true.,.true.,.true.]) 

        ! Segmentation fault, or answer '0': 

        write(*,*) 'C2: ', my_sum(input) 

end program test_my_sum

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]