[PATCH] D123088: attributes: introduce allockind attr for describing allocator fn behavior

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 05:38:36 PDT 2022


nikic added inline comments.


================
Comment at: llvm/docs/LangRef.rst:1584
+     * "alloc": the function returns a new block of memory, or null if the
+       allocation fails
+     * "realloc": the function returns a new block of memory or null. If the
----------------
aykevl wrote:
> Is it worth saying something about `alloc(0)`? C `malloc(0)` may or may not return NULL depending on the implementation:
> 
> > If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned to indicate an error, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.
I guess we may want to omit the "if the allocation fails" here (and just make null a valid value -- unless the return is nonnull of course), but I don't think a more specific guarantee on the behavior of zero-sized allocations is needed for the kinds of optimizations we're interested in performing. Or do you have something in mind where this would matter?

For reference, the wording for `allocsize` is:
> This attribute indicates that the annotated function will always return at least a given number of bytes (or null)

It does not further specify in which cases null/non-null may be returned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123088



More information about the llvm-commits mailing list