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

            Bug ID: 101135
           Summary: Use of absent assumed-shape array argument as an
                    actual argument for an optional dummy argument
                    mistakenly flagged as error by
                    UndefinedBehaviourSanitizer
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcel.jacobse at ewetel dot net
  Target Milestone: ---

Compiling and running the minimal example

program main
    implicit none
    call test_wrapper

contains
    subroutine test_wrapper(y)
        real, dimension(1), intent(out), optional :: y
        call test(y)
    end subroutine test_wrapper

    subroutine test(y)
        real, dimension(:), intent(out), optional :: y
        if (present(y)) y=0
    end subroutine test
end program

with -fsanitize=undefined on any gfortran version since 8.1.0 produces this
false positive:

/app/example.f90:8:20: runtime error: load of null pointer of type
'real(kind=4)'

See for example: https://godbolt.org/z/aqGE18EGG

The issue disappears on gfortran version 7.3.0 and earlier, and also if 'y' in
'test' is not an assumed-shape array, for example if replacing 'dimension(:)'
by 'dimension(1)'. See also
https://stackoverflow.com/questions/68046152/is-passing-an-absent-assumed-shape-array-for-an-optional-argument-of-another-pro

Unfortunately I am not sure if this is an issue with gfortran itself or moreso
a false positive by UndefinedBehaviourSanitizer. So perhaps this report should
rather be for the "sanitizer" component, sorry if that is the case.

Reply via email to