[PATCH] D54533: InstCombine: don't assume malloc will never return nullptr

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 14 08:49:45 PST 2018


t.p.northover created this revision.
Herald added subscribers: hiraditya, mcrosier.

We've got some code that tries to eliminate unused allocations by inspecting their uses. Unfortunately one of the uses it checks is an `icmp`, where the code currently assumes that an allocation will never return nullptr. This isn't correct. Most obviously out of memory errors are signalled by nullptr on many systems, but even when the kernel is willing to oversubscribe physical RAM malloc will return nullptr for a large enough single request.

In fact, I believe only certain variants of the C++ operator new never return nullptr (because they throw in error cases). So this patch limits that particular `icmp` check to the cases where the allocation function is known to be safe.


Repository:
  rL LLVM

https://reviews.llvm.org/D54533

Files:
  llvm/include/llvm/Analysis/MemoryBuiltins.h
  llvm/lib/Analysis/MemoryBuiltins.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/badmalloc.ll
  llvm/test/Transforms/InstCombine/compare-unescaped.ll
  llvm/test/Transforms/InstCombine/malloc-free-delete.ll
  llvm/test/Transforms/InstCombine/malloc-new.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54533.174048.patch
Type: text/x-patch
Size: 7074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181114/859e577d/attachment.bin>


More information about the llvm-commits mailing list