[llvm-bugs] [Bug 34581] New: LLVM miscompiles calls to "operator delete" under -Oz

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 12 13:04:33 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34581

            Bug ID: 34581
           Summary: LLVM miscompiles calls to "operator delete" under -Oz
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170912/8b83bb04/attachment.html>


More information about the llvm-bugs mailing list