<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 - LLVM miscompiles calls to "operator delete" under -Oz"
   href="https://bugs.llvm.org/show_bug.cgi?id=34581">34581</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM miscompiles calls to "operator delete" under -Oz
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Test case:

void f(char *c) {
  delete c;
}

void g(char *c) {
  if (c)
    ::operator delete(c);
}

void h(char *c) {
  if (c)
    delete c;
}

At -Oz, LLVM optimizes away the implied "if (c)" in f. It's highly questionable
for LLVM to be doing this, but a C++ implementation is permitted to elide the
null check in this case.

LLVM also optimizes away the explicit "if (c)" in g, which is a miscompile. A
user replacement operator delete may have observable effects (for instance,
logging) even when called on a null pointer, so LLVM is not allowed to invent
calls to it. Note that in this case the "operator delete" invocation is
"nobuiltin", making it doubly-clear that this is a miscompile.

Finally, it optimizes away both null checks in h, which again is a miscompile.
Despite being a builtin call, this is still an incorrect transformation, again
because operator delete can have observable side-effects.</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>