<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/134991>134991</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang][OpenMP][debug] Invalid debug info for variable size string in target region.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            abidh
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          abidh
      </td>
    </tr>
</table>

<pre>
    For variable size strings, flang generates an artificial variable in the debug info that holds the length. While reviewing https://github.com/llvm/llvm-project/pull/134967, I noticed that variable inside the target region are using the artificial variable in the host for the length which is not working. As a result, the evaluation fails. The problem could be reproduced with the following program but it will need the changes in #134967 to compile.

```
module test
  implicit none

 contains

  subroutine TestOfCharacter(a0, a1, l)
    character(len=*), intent(in) :: a0
    character(len=*), intent(inout):: a1
    integer, intent(in) :: l

    !$omp target map(to:a0) map(from: a1)
      a1 = a0
 !$omp end target

  end subroutine TestOfCharacter
end module test

program main
  use test
  character(len=15) :: first
 character(len=:), allocatable :: second
  first = 'Short string'
 second='This is a large string.'
  call TestOfCharacter(first, second, 23)
 print *, first
  print *, second
end program
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVF2vozYQ_TXOy6gIDNyEBx7YXEXah2or9Up9HmCAaY2N7CFR--srE3JvVvshrYTyMZ6Pc86YgyHwaIlqVX5SWmPL_aS0VuXrAVeZnK-30KF1_b_1xXm4omdsDUHg_wiCeLZjUPoMg0E7wkiWPAoFQAvohQfuGM1HGVuQiaCndh2B7eBAJhSYnOnDdmLIjjIl8NfEhsDTlenGdoRJZAkqb5S-KH0ZWaa1TTo3K30x5vr4-m3x7m_qROnLshqj9CXLi-rlGBF-BuuEO-rvI58gBe5pGy7oRxLwNLKL-AnWEIfHs5-wmVwQGJx_IgC3ibsJOMShcHP-H7ZjAk0ABE9hNRIhxXy6ollR4sAB2YQE3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