This is an archive of the discontinued LLVM Phabricator instance.

[BuildLibCalls] Add noundef to allocator fns' size
ClosedPublic

Authored by aqjune on Feb 19 2021, 5:00 AM.

Details

Summary

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.

Diff Detail

Event Timeline

aqjune created this revision.Feb 19 2021, 5:00 AM
aqjune requested review of this revision.Feb 19 2021, 5:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2021, 5:00 AM

I wanted to add noundef to C++ new operators, but a former discussion said attributes of these should be inserted by the frontend.
Since I wasn't friendly with the clang code, I found Sema::FindAllocationFunctions which lists possible new operator functions and matches the right one, but couldn't find the place that actually adds attributes to these.
A question is - there is already an ongoing effort for adding noundef to C/C++ function arguments, and would it automatically resolve this case? Otherwise, where should I update to add noundef to new operator arguments?

This revision is now accepted and ready to land.Feb 19 2021, 7:42 AM
This revision was landed with ongoing or failed builds.Feb 22 2021, 8:58 PM
This revision was automatically updated to reflect the committed changes.
tra added a subscriber: tra.Feb 23 2021, 9:33 AM

FYI, this change broke CUDA compilation with recent CUDA versions (versions before CUDA-10.2 seem to work). I don't know what wexactly went wrong yet.

http://lab.llvm.org:8011/#/builders/1/builds/6671

tra added a comment.Feb 23 2021, 1:18 PM
In D97045#2582287, @tra wrote:

FYI, this change broke CUDA compilation with recent CUDA versions (versions before CUDA-10.2 seem to work). I don't know what wexactly went wrong yet.

http://lab.llvm.org:8011/#/builders/1/builds/6671

False alarm. The bots were failing due to an unrelated infrastructure change.

Okay, thanks for letting me know..!