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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Bad function result for call to memcpy
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Here's a test program:
```
program test_memcpy
  use iso_c_binding
  interface
    function memcpy(dest, src, len) bind(c)
      import c_ptr
      type(c_ptr), value :: dest, src
      integer(kind=4), value :: len
      type(c_ptr) memcpy
    end
  end interface
  integer(kind=4), target :: src, dest
  type(c_ptr) tmp
  src = 343
  tmp = memcpy(c_loc(dest), c_loc(src), 4)
  if (c_associated(tmp, c_loc(dest))) then
    print *, "OK"
  else
    print *, "Bad memcpy result"
    print *, "memcpy result: ", tmp
    print *, "c_loc(dest): ", c_loc(dest)
  end if
end
```
When I compile and execute it with gfortran, it prints "OK".  But I get messages that start with "Bad memcpy result" when I do: "flang-new -L lib && a.out".

@PeixinQiao, is this in your area?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1VMGOmzAQ_Rq4jDYiBgI5cMg2WrVqpbanHiNjJsStwcg2u83fd-wQwmYbCTl4Zt68Nw87tW7O1Wc0GLHCAgeH1sFgdGt4F6W7KNlHyS7aJNMTtlM61B467MRwviQARosgrT6IQy37RvbtNSF7h-bIBV4DAMexF07qHqYWrGyoYcQ-gTXC_yjsI7YF34mSFNrewNSxG7RxIA6DM8u4Ow_oy0OcINTolasRwY-T7mBJsmxHAlskRPnH86X77H9gL-kxF7w3AwCp07Sh148mPCR13LTorqyTH0H5hLxndt1wTVE1AfeQZulc3Q0hNDstDkqL2fFAeQ0FshDJFo7LIwQYt1YLyR36T-JJF8i52TYoOi29GgzNSi12HhAx9v0rLbM3yuLj0mfeTMLBoB2VWyA_Vr-vJPN8tXf0ZtBH0P0EN9h9Zvk1j5fd_JHvrskvMgC-gNDdIBUCJwj-RTE6uiIO3qQ7QXukI2x475mku8iysz0rgOfRUQt_FDq0lrdoyVfuwNIBmXo8cAjeLvSNnqY5Kt63Tz2-wdM3ULKm2IYe4Cs9esBqGuKyZskPlH9l_1NyHdR5YlpkD2c9GuAGeZS-xFitN5siYyzdlnFTpc023fLYSaewivLnQBrle_AS5wt_EQk0PAiuFDg9yY9Ho6qTc4P1J5-90NPSjGO9Ihdpo9Tr9eeJ_oV-oyDlL9LaES295GVRsPhUJamoUybKvMkY1muxxaLEpGyKrN4IJH2K13TmvEAa3FsSWvhPnu9jWbGEsfWaliRP1-WqwByzvMxylhYN55zMwY5LtfI6Vtq0samCpHpsLSWVtM7eknRlZNtj8MP356M7aVMN1qHsj6iaOLBXQf0_TtWmaA">