https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92887
--- Comment #2 from anlauf at gcc dot gnu.org --- Created attachment 55356 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55356&action=edit Partial patch for the presence attribute The attached patch generates a test for the presence that depends on the allocation or association status of the argument. An extended testcase however shows that we mishandle the VALUE attribute: we do not generate a proper temporary: program p implicit none (type, external) integer, allocatable :: aa integer, pointer :: pp character, allocatable :: ca character, pointer :: cp nullify (pp, cp) call sub (aa, pp, ca, cp) allocate (aa, pp, ca, cp) aa = 1; pp = 2; ca = "a"; cp = "b" call foo (3, 4, "a", "b") call foo (aa, pp, ca, cp) call bar (5, 6, "c", "d") call bar (aa, pp, ca, cp) call bla (7, 8, "e", "f") call bla (aa, pp, ca, cp) deallocate (aa, pp, ca, cp) contains subroutine sub (x, y, c, d) integer, value, optional :: x, y character, value, optional :: c, d if (present(x)) stop 1 if (present(y)) stop 2 if (present(c)) stop 3 if (present(d)) stop 4 end subroutine foo (x, y, c, d) integer, value, optional :: x, y character, value, optional :: c, d if (.not. present(x)) stop 1 if (.not. present(y)) stop 2 if (.not. present(c)) stop 3 if (.not. present(d)) stop 4 print *, "value+optional:", x, y, c, d end subroutine bar (x, y, c, d) integer, value :: x, y character, value :: c, d print *, "value :", x, y, c, d end subroutine bla (x, y, c, d) integer :: x, y character :: c, d print *, "no value :", x, y, c, d end end Executing this testcase shows junk for the character variable, and inspection of the tree dump shows that this is not limited to it...