[llvm-dev] [RFC] Adding support for marking allocator functions in LLVM IR

Bryce Wilson via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 7 01:23:22 PST 2022


Hi all,

It's quite a coincidence to see this proposal. I just joined this list a few days ago specifically to ask about the correct way to annotate allocation and freeing functions. I'll create a separate thread to ask questions about my specific situation but I wanted to add my support for this proposal here.

My main question is if there should be some way to specify the kind of allocation function. In the hardcoded AllocationFnData array, there is a field to specify if the function acts like malloc, new, calloc, realloc, etc. This could be added to the annotation but I think a better way would be to specify the actual properties of interest. Can it return null, does it align the allocation, and what are the values in the newly allocated space (undef for malloc, 0 for calloc, something unknown but defined for strdup). This would also allow for creating new types of allocators that don't already exist.

I've created a patch with what this might look like for the existing hardcoded functions here: https://reviews.llvm.org/D116797 <https://reviews.llvm.org/D116797>. In my initial implementation, I realized that there are a lot of places where argument positions are hardcoded and special detection of strdup and strndup is hardcoded. Regardless of if we add the ability to specify these properties in attribute form or not, we will at least need to ensure that the correct arguments are used based on an allocsize annotation if available.

Sincerely,
Bryce Michael Wilson

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20220107/6ba100d6/attachment.html>


More information about the llvm-dev mailing list