[BuildLibCalls] Add noundef to allocator fns' size
authorJuneyoung Lee <aqjune@gmail.com>
Fri, 19 Feb 2021 07:41:19 +0000 (16:41 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Tue, 23 Feb 2021 04:58:03 +0000 (13:58 +0900)
commit481c62277d5669e15e6a0ec14240c5f5410ca954
tree6bca8e1d36d42784231cbfaeeade43aedd97b994
parent468fa037b2a15a40f17329a995d058dda6049d28
[BuildLibCalls] Add noundef to allocator fns' size

This is a patch to explicitly mark the size parameter of allocator functions like malloc/realloc/... as noundef.

For C/C++: undef can be created from reading an uninitialized variable or padding.
Calling a function with uninitialized variable is already UB.
Calling malloc with padding value is.. something that's not expected. Padding bits may appear in a coerced aggregate, which doesn't apply to malloc's size.
Therefore, malloc's size can be marked as noundef.

For transformations that introduce malloc/realloc/..: I ran LLVM unit tests with an updated Alive2 semantics, and found no regression, so it seems okay.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D97045
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/test/Transforms/InferFunctionAttrs/annotate.ll