[PATCH] D97045: [BuildLibCalls] Add noundef to allocator fns' size

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 05:00:12 PST 2021


aqjune created this revision.
aqjune added reviewers: jdoerfert, rsmith, xbolva00.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97045

Files:
  llvm/lib/Transforms/Utils/BuildLibCalls.cpp
  llvm/test/Transforms/InferFunctionAttrs/annotate.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97045.324955.patch
Type: text/x-patch
Size: 6482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210219/41c8c5a5/attachment.bin>


More information about the llvm-commits mailing list