<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Cherry-pick 3522167efd80e2fef42a865cdf7481d60d062603 to release/12.x"
   href="https://bugs.llvm.org/show_bug.cgi?id=50789">50789</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cherry-pick 3522167efd80e2fef42a865cdf7481d60d062603 to release/12.x
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lxfind@gmail.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lxfind@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>49317
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Please cherry-pick this to the 12.x releases:

commit 3522167efd80e2fef42a865cdf7481d60d062603
Author: Xun Li <<a href="mailto:lxfind@gmail.com">lxfind@gmail.com</a>>
Date:   Thu Jun 17 19:06:10 2021 -0700

    [Coroutine] Properly deal with byval and noalias parameters

    This patch is to address <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - miscompile with coroutines (aarch64, x86_64)"
   href="show_bug.cgi?id=48857">https://bugs.llvm.org/show_bug.cgi?id=48857</a>.
    Previous attempts can be found in D104007 and D101980.
    A lot of discussions can be found in those two patches.
    To summarize the bug:
    When Clang emits IR for coroutines, the first thing it does is to make a
copy of every argument to the local stack, so that uses of the arguments in the
function will all refer to the local copies instead of the arguments directly.
    However, in some cases we find that arguments are still directly used:
    When Clang emits IR for a function that has pass-by-value arguments,
sometimes it emits an argument with byval attribute. A byval attribute is
considered to be local to the function (just like alloca) and hence it can be
easily determined that it does not alias other values. If in the IR there
exists a memcpy from a byval argument to a local alloca, and then from that
local alloca to another alloca, MemCpyOpt will optimize out the first memcpy
because byval argument's content will not change. This causes issues because
after a coroutine suspension, the byval argument may die outside of the
function, and latter uses will lead to memory use-after-free.
    This is only a problem for arguments with either byval attribute or noalias
attribute, because only these two kinds are considered local. Arguments without
these two attributes will be considered to alias coro_suspend and hence we
won't have this problem. So we need to be able to deal with these two
attributes in coroutines properly.
    For noalias arguments, since coro_suspend may potentially change the value
of any argument outside of the function, we simply shouldn't mark any argument
in a coroutiune as noalias. This can be taken care of in CoroEarly pass.
    For byval arguments, if such an argument needs to live across suspensions,
we will have to copy their value content to the frame, not just the pointer.

    Differential Revision: <a href="https://reviews.llvm.org/D104184">https://reviews.llvm.org/D104184</a></pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta] 12.0.1 Release Blockers"
   href="https://bugs.llvm.org/show_bug.cgi?id=49317">Bug 49317</a>] [meta] 12.0.1 Release Blockers
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>