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

            Bug ID: 118321
           Summary: [OpenMP] declare_variant's 'adjust_args' yields wrong
                    code if the result is passed by argument
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: parras at gcc dot gnu.org
  Target Milestone: ---

The function
    character(:) function g (a,b,c,d,e)

passes the result variable as argument, i.e. the tree dump looks like:

   void g (character(kind=1)[1:..__result] * & __result,
           integer(kind=8) * .__result,
           character(kind=1)[1:_a] & restrict a,
           void * b, void * c, void * d,
           character(kind=1)[1:_e] & restrict e,
           integer(kind=8) _a, integer(kind=8) _e)

But that's not honored such that adjust_args's need_device_ptr processes the
wrong variable:

   f (&pstr.1, &slen.0, &D.4875, x, y, z, &"cde"[1]{lb: 1 sz: 1}, 3, 3);

The 'D.xxx' should be for 'y' not for the &"abc" string.

* * *

module m
  use iso_c_binding
contains
  character(:) function f (a,b,c,d,e)
    allocatable :: f
    character(*) :: a, e
    type(c_ptr), value :: b,c,d
  end
  character(:) function g (a,b,c,d,e)
    !$omp declare variant(f) match(construct={dispatch})  &
    !$omp&                   adjust_args(need_device_ptr : c)
    allocatable :: g
    character(*) :: a, e
    type(c_ptr), value :: b,c,d
  end
end module m

use m
type(c_ptr) :: x,y,z
character(len=:), allocatable :: str
!$omp dispatch
  str = g("abc", x, y, z, "cde")
end

Reply via email to