<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 - SmallVector: use-after-poison MSAN error in destructor"
   href="https://bugs.llvm.org/show_bug.cgi?id=35889">35889</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SmallVector: use-after-poison MSAN error in destructor
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Core LLVM classes
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>steve@obrien.cc
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The topmost class, `SmallVector`, has internal storage for some elements; `N -
1` elements' bytes worth of space.  Meanwhile a base class
`SmallVectorTemplateCommon` has room for one element as well, totaling `N`
elements' worth of space.

The space for the N elements is contiguous and straddles
`SmallVectorTemplateCommon` and `SmallVector`.

A class "between" those two owning the storage, `SmallVectorImpl`, in its
destructor, calls the destructor for elements contained in the vector, if any. 
It uses `destroy_range(begin, end)` to destroy all items in sequence, starting
from the end.

By the time the destructor for `SmallVectorImpl` is running, though, the memory
for elements `[1, N)` is already poisoned, due to `SmallVector`'s destructor
having done its thing already.

So if the element type `T` has a nontrivial destructor that accesses any
members of the `T` instance being destroyed, we'll run into a use-after-poison
bug.

This patch moves the destruction loop into `SmallVector`'s destructor, so any
memory being accessed while dtors are running is not yet poisoned.

[Phabricator diff and repro steps coming]</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>