<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 - [coroutines] optimized code references subobject of promise as temporary"
   href="https://bugs.llvm.org/show_bug.cgi?id=47085">47085</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[coroutines] optimized code references subobject of promise as temporary
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

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

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>me@xecycle.info
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23834" name="attach_23834" title="reproducing source code">attachment 23834</a> <a href="attachment.cgi?id=23834&action=edit" title="reproducing source code">[details]</a></span>
reproducing source code

Using 10.0.1 as packaged by Arch Linux, attached code when compiled with
"-std=gnu++17 -fcoroutines-ts -O2 -stdlib=libc++" triggers use-after-free
reports in valgrind, but runs ok at -O0.  It has

__attribute__((noinline))
void f(std::string s, coroutine_handle<> h)
{
  puts(s.c_str());
  h.destroy();
}

and

      void await_suspend(coroutine_handle<> h)
      {
        f(std::move(pr->retval), h);
      }

Here, calling f() needs a temporary std::string, copied from member of
coroutine promise; at -O0 it is created by alloca, but at -O2 it points to the
original object, and destroyed after returned from f().  Because f() freed the
coroutine, ~std::string() caused a use-after-free.</pre>
        </div>
      </p>


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

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