Add pg_attribute_returns_nonnull to various memory allocation functions This function attribute tells the compiler that the function will never return NULL. This allows the compiler to do better static analysis and lets it optimize the caller given the non-NULL guarantee.
The attribute is placed in front of the declaration, rather than after it, so that it can also expand to the MSVC annotation _Ret_notnull_, which is only valid in that position. Only functions that raise an error on allocation failure are marked. Functions that take a flags argument, such as palloc_extended() and palloc_mul_extended(), can return NULL when MCXT_ALLOC_NO_OOM is passed and are therefore not marked. Author: Tristan Partin <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/DJROV5LUO7B5.DIWXYC0101KD%40partin.io Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/23192ac644e2a8f0597692aacb269321ee5acd99 Modified Files -------------- src/include/c.h | 15 +++++++++++++++ src/include/common/fe_memutils.h | 32 ++++++++++++++++---------------- src/include/utils/palloc.h | 32 ++++++++++++++++---------------- 3 files changed, 47 insertions(+), 32 deletions(-)
