[Bug fortran/92887] New: [F2008] Passing nullified/disassociated pointer or unalloc allocatable to OPTIONAL + VALUE dummy fails

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 10 13:40:00 GMT 2019


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

            Bug ID: 92887
           Summary: [F2008] Passing nullified/disassociated pointer or
                    unalloc allocatable to  OPTIONAL + VALUE dummy fails
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Cf. PR 44666, except that one this time has a VALUE in addition.

The following program segfaults at run time as 'aa' and 'pp' are dereferenced.

It should pass '0'* as absent argument plus false to the hidden _argument.

Cf. F2018, 15.5.2.12, Paragraph 1:
"A dummy argument […] is not present if the dummy argument […]
 * does not have the ALLOCATABLE or POINTER attribute, and corresponds to an
   actual argument that
   – has the ALLOCATABLE attribute and is not allocated, or
   – has the POINTER attribute and is disassociated;"

Cf. gfc_conv_procedure_call and search for:
              /* For scalar arguments with VALUE attribute which are passed by
                 value, pass "0" and a hidden argument gives the optional
                 status.  */

[* also CHARACTER or derived types are currently passed by value, but I think
   they should be copied + passed by reference, cf. PR91196 and possibly
   others. Likewise for arrays, but those are not yet supported with VALUE,
   cf. PR 92702]


implicit none (type, external)
integer, allocatable :: aa
integer, pointer :: pp
nullify(pp)
call sub(aa, pp)
contains
subroutine sub(x, y)
  integer, value, optional :: x, y
  if (present(x)) stop 1
  if (present(y)) stop 2
end subroutine sub
end


More information about the Gcc-bugs mailing list