[Attributor][FIX] Handle non-pointers when following uses
When we follow uses, e.g., in AAMemoryBehavior or AANoCapture, we need
to make sure the value is a pointer before we ask for abstract
attributes only valid for pointers. This happens because we follow
pointers through calls that do not capture but may return the value.
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 46e5c16..c65925b 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -5074,10 +5074,14 @@
// general capturing of the underlying argument. The reason is that the
// call might the argument "through return", which we allow and for which we
// need to check call users.
- unsigned ArgNo = ICS.getArgumentNo(U);
- const auto &ArgNoCaptureAA =
- A.getAAFor<AANoCapture>(*this, IRPosition::callsite_argument(ICS, ArgNo));
- return !ArgNoCaptureAA.isAssumedNoCapture();
+ if (U->get()->getType()->isPointerTy()) {
+ unsigned ArgNo = ICS.getArgumentNo(U);
+ const auto &ArgNoCaptureAA = A.getAAFor<AANoCapture>(
+ *this, IRPosition::callsite_argument(ICS, ArgNo));
+ return !ArgNoCaptureAA.isAssumedNoCapture();
+ }
+
+ return true;
}
void AAMemoryBehaviorFloating::analyzeUseIn(Attributor &A, const Use *U,
@@ -5123,9 +5127,12 @@
// Adjust the possible access behavior based on the information on the
// argument.
- unsigned ArgNo = ICS.getArgumentNo(U);
- const IRPosition &ArgPos = IRPosition::callsite_argument(ICS, ArgNo);
- const auto &MemBehaviorAA = A.getAAFor<AAMemoryBehavior>(*this, ArgPos);
+ IRPosition Pos;
+ if (U->get()->getType()->isPointerTy())
+ Pos = IRPosition::callsite_argument(ICS, ICS.getArgumentNo(U));
+ else
+ Pos = IRPosition::callsite_function(ICS);
+ const auto &MemBehaviorAA = A.getAAFor<AAMemoryBehavior>(*this, Pos);
// "assumed" has at most the same bits as the MemBehaviorAA assumed
// and at least "known".
intersectAssumedBits(MemBehaviorAA.getAssumed());