Skip to content

[Flang] Execution error when a variable with optional and pointer attributes defined is used as an argument to a subroutine #110441

@ohno-fj

Description

@ohno-fj
Version of flang-new : 20.0.0(2603c8b23be06116bc61bda36fae05b81d906c3f)/AArch64

When a variable with optional and pointer attributes defined is used as an argument to a subroutine, a run-time error occurs (Segmentation fault (core dumped)).
When pointer attribute is changed to allocatable attribute, the execution also fails.
When pointer and allocatable attributes are not specified, the execution succeeds.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

F01_12.f90:

program main
  call sub3()
  print*,"Pass"
contains
  subroutine sub3(ptr)
    integer,optional,pointer :: ptr(:)       ! Segmentation fault
!    integer,optional,allocatable :: ptr(:)  ! Segmentation fault
!    integer,optional :: ptr(:)              ! OK
    call sub(ptr)
  end subroutine sub3
  subroutine sub(dmy)
    integer,optional::dmy(:)
    write(6,*) "present(dmy) = ", present(dmy)
  end subroutine sub
end program main
$ flang-new F01_12.f90; ./a.out
Segmentation fault (core dumped)
$
$ gfortran F01_12.f90; ./a.out
 present(dmy) =  F
 Pass
$
$ ifort -diag-disable=10448 F01_12.f90; ./a.out
 present(dmy) =  F
 Pass
$

Metadata

Metadata

Assignees

No one assigned

    Labels

    flangFlang issues not falling into any other categoryquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions