[llvm-bugs] [Bug 41039] New: instcombine incorrectly removes "dead" malloc/operator delete pair

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 11 14:33:00 PDT 2019


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

            Bug ID: 41039
           Summary: instcombine incorrectly removes "dead" malloc/operator
                    delete pair
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: efriedma at quicinc.com
                CC: llvm-bugs at lists.llvm.org

Testcase:

#include <cstddef>
#include <cstdio>
#include <cstdlib>
void* operator new(size_t sz) {
  printf("Calling new\n");
  return malloc(sz);
}
__attribute__((noinline))
void operator delete(void* ptr) noexcept {
  printf("Calling delete\n");
  return free(ptr);
}
int* f() { return new int; }
int main() { delete f(); }

With "clang -O2", outputs "Calling new", but not "Calling delete".  I think
this is a bug according to the standard: we're allowed to remove dead
new/delete pairs, but we have to either remove a complete pair, or nothing at
all.

I think this is a bug in instcombine, that it considers any pair of
allocation/deallocation function to be dead, even if that pair is something
like malloc/operator delete.

-- 
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/20190311/7fe782cd/attachment.html>


More information about the llvm-bugs mailing list