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

--- Comment #13 from anlauf at gcc dot gnu.org ---
Returning to this PR, I found that passing NULL() to character pointer dummies
exhibits a wrong translation of the function call, despite the declaration
appearing fine:

program p
implicit none
  character(10), pointer :: c => NULL()
  character(:),  pointer :: d => NULL()

  ! these are incorrectly translated and may crash at runtime:
  call foo (null(c))
  call bla (null(c))
  call bar (null(d))
  call bla (null())
  call bar (null())

  ! correctly translated function calls:
  call foo (c)
  call bla (c)
  call bar (d)
contains
  subroutine foo (x)
    character(len=*), pointer, intent(in) :: x
    if (associated (x)) stop 1
  end
  subroutine bla (x)
    character(len=10), pointer, intent(in) :: x
    if (associated (x)) stop 2
  end
  subroutine bar (x)
    character(len=:), pointer, intent(in) :: x
    if (associated (x)) stop 3
  end
end

The dump of the relevant part of the main is:

void p ()
{
  static void bar (character(kind=1) * &, integer(kind=8) *);
  static void bla (character(kind=1)[1:10] * &, integer(kind=8));
  static void foo (character(kind=1)[1:] * &, integer(kind=8));
  static character(kind=1)[1:10] * c = 0B;
  static integer(kind=8) _F.d;
  static character(kind=1) * d = 0B;

  foo (0B);
  bla (0B);
  bar (0B);
  {
    static void * C.4802 = 0B;

    bla (&C.4802);
  }
  {
    static void * C.4803 = 0B;

    bar (&C.4803);
  }
  foo (&c, 10);
  bla (&c, 10);
  bar (&d, &_F.d);
}

Reply via email to