Skip to content

Commit

Permalink
IR: Have byref imply dereferenceable
Browse files Browse the repository at this point in the history
The langref already states it does, but this wasn't implemented. Also
covers inalloca and preallocated. Also helps fix a dependence on
pointer element types.
  • Loading branch information
arsenm committed Sep 24, 2020
1 parent d65a700 commit dc08185
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 65 deletions.
13 changes: 9 additions & 4 deletions llvm/lib/IR/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,16 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes();
if (DerefBytes == 0 && (A->hasByValAttr() || A->hasStructRetAttr())) {
Type *PT = cast<PointerType>(A->getType())->getElementType();
if (PT->isSized())
DerefBytes = DL.getTypeStoreSize(PT).getKnownMinSize();
if (DerefBytes == 0) {
// Handle byval/byref/inalloca/preallocated arguments
if (Type *ArgMemTy = A->getPointeeInMemoryValueType()) {
if (ArgMemTy->isSized()) {
// FIXME: Why isn't this the type alloc size?
DerefBytes = DL.getTypeStoreSize(ArgMemTy).getKnownMinSize();
}
}
}

if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes();
CanBeNull = true;
Expand Down
Loading

0 comments on commit dc08185

Please sign in to comment.