[PATCH] D63668: [Support] Improve zero-size allocation with safe_malloc, etc.

Hubert Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 08:57:17 PDT 2019


hubert.reinterpretcast added a comment.

> Just a quick grep of only safe_malloc, it seems like none of its clients would ever call it with 0 in a normal circumstance, although I may be wrong here.

The call to `safe_calloc` in https://llvm.org/doxygen/SparseSet_8h_source.html can request 0 bytes in a "normal circumstance". This change solves a portability issue with these functions as-is. Requiring a change to the client code to never pass in zero is a change in the contract of these functions. It is not definitively wrong for the client code to request zero bytes, and requiring the client code to add extra special-case handling can have drawbacks.

The change in this patch is within the scope of being a bug fix, and the implications of the change is rather well understood. A change to add the assertion that the request was not for zero bytes will broadly affect platforms where the system `malloc` //does// perform allocation when asked for zero bytes, the impact of which is not entirely known. What //is// known is that there is existing client code that would need additional changes should the assertion be added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63668/new/

https://reviews.llvm.org/D63668





More information about the llvm-commits mailing list