Skip to content

Commit da60ef5

Browse files
committed
!fixup address comments, thanks!
1 parent 4b985f7 commit da60ef5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

llvm/docs/LangRef.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,9 @@ Currently, only the following parameter attributes are defined:
14741474
``null_pointer_is_valid`` function attribute is present.
14751475
``n`` should be a positive number. The pointer should be well defined,
14761476
otherwise it is undefined behavior. This means ``dereferenceable(<n>)``
1477-
implies ``noundef``. When ``dereferenceable(<n>)`` is used in an
1478-
:ref:`assume operand bundls <assume_opbundles>`, the pointer is only
1479-
guaranteed to be dereferenceable at the point of the assumption and
1480-
may not be dereferenceable at later pointers, e.g. because it could have
1481-
been freed.
1477+
implies ``noundef``. When used in an assume operand bundle, more restricted
1478+
semantics apply. See :ref:`assume operand bundles <assume_opbundles>` for
1479+
more details.
14821480

14831481
``dereferenceable_or_null(<n>)``
14841482
This indicates that the parameter or return value isn't both
@@ -2930,6 +2928,11 @@ the behavior is undefined, unless one of the following exceptions applies:
29302928
(including a zero alignment). If this is the case, then the pointer value
29312929
must be a null pointer, otherwise the behavior is undefined.
29322930

2931+
* ``dereferenceable(<n>)`` operand bundles only guarantee the pointer is
2932+
dereferenceable at the point of the assumption and may not be
2933+
dereferenceable at later pointers, e.g. because it could have been
2934+
freed.
2935+
29332936
In addition to allowing operand bundles encoding function and parameter
29342937
attributes, an assume operand bundle my also encode a ``separate_storage``
29352938
operand bundle. This has the form:

llvm/lib/Analysis/Loads.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ static bool isDereferenceableAndAlignedPointer(
169169
Size, DL, CtxI, AC, DT, TLI,
170170
Visited, MaxDepth);
171171

172+
// Dereferenceable information from assumptions is only valid if the value
173+
// cannot be freed between the assumption and use. For now just use the
174+
// information for values that cannot be freed in the function.
175+
// TODO: More precisely check if the pointer can be freed between assumption
176+
// and use.
172177
if (CtxI && !V->canBeFreed()) {
173178
/// Look through assumes to see if both dereferencability and alignment can
174179
/// be proven by an assume if needed.

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
626626
*I, I->bundle_op_info_begin()[Elem.Index])) {
627627
if (RK.WasOn == V &&
628628
(RK.AttrKind == Attribute::NonNull ||
629-
(RK.AttrKind == Attribute::Dereferenceable && !V->canBeFreed() &&
629+
(RK.AttrKind == Attribute::Dereferenceable &&
630630
!NullPointerIsDefined(Q.CxtI->getFunction(),
631631
V->getType()->getPointerAddressSpace()))) &&
632632
isValidAssumeForContext(I, Q.CxtI, Q.DT))

0 commit comments

Comments
 (0)