Example
define dso_local noalias i8* @_Z6maixxnv() local_unnamed_addr #0 {
entry:
%call = tail call noalias dereferenceable_or_null(64) i8* @malloc(i64 64) #6 ret i8* %call
}
Paths
| Differential D66651
Annotate return values of allocation functions with dereferenceable_or_null ClosedPublic Authored by xbolva00 on Aug 23 2019, 6:50 AM.
Details Summary Example %call = tail call noalias dereferenceable_or_null(64) i8* @malloc(i64 64) #6 ret i8* %call }
Diff Detail
Event TimelineComment Actions I will update/add tests after some initial code review.
Comment Actions It seems inconsistent to declare Op0C initially and Op1C late given that both are need 2 times in almost the same fashion. We also need tests. I think this is the right thing to do though, dereferenceability will be used for LICM and AA (D66157), and nonnull can be eliminated with any access or null check (D65402 and following). Comment Actions I'm not an LLVM person, but I just wanted to double-check: is this correct even in the face of situations where malloc() and friends return a non-null pointer that is *not* dereferenceable? e.g., when someone calls malloc(0) with certain libc implementations? Comment Actions We ignore malloc(0), realloc(p, 0), etc cases (no annotation, deref_or_null(0) is useless). All edge cases should be coveree in deref-alloc-fns.ll. We annotate if size is known constant and > 0. Comment Actions Fixed function names in new tests. (op_new_constant_size and op_new_constant_zero_size was swapped). Comment Actions Two last comments from my side.
Comment Actions Last problem mentioned below. Otherwise, LGTM.
This revision is now accepted and ready to land.Aug 27 2019, 12:10 PM Closed by commit rL370168: Annotate return values of allocation functions with dereferenceable_or_null (authored by xbolva00). · Explain WhyAug 28 2019, 1:27 AM This revision was automatically updated to reflect the committed changes.
xbolva00 added inline comments.
xbolva00 added inline comments.
Revision Contents
Diff 217578 llvm/trunk/include/llvm/Analysis/MemoryBuiltins.h
llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/compare-unescaped.ll
llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll
llvm/trunk/test/Transforms/InstCombine/malloc-free-delete.ll
llvm/trunk/test/Transforms/InstCombine/objsize.ll
llvm/trunk/test/Transforms/InstCombine/realloc.ll
|
What if one is NULL but the other not? Will getWithDereferenceableOrNullBytes(0) do the right thing?