static void annotateDereferenceableBytes(CallInst *CI,
ArrayRef<unsigned> ArgNos,
- uint64_t DerefBytes) {
+ uint64_t DereferenceableBytes) {
for (unsigned ArgNo : ArgNos) {
+ uint64_t DerefBytes = std::max(
+ CI->getDereferenceableOrNullBytes(ArgNo + AttributeList::FirstArgIndex),
+ DereferenceableBytes);
+
if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) <
DerefBytes) {
CI->removeParamAttr(ArgNo, Attribute::Dereferenceable);
define i32 @memcmp_const_size_no_update_deref2(i8* nocapture readonly %d, i8* nocapture readonly %s) {
; CHECK-LABEL: @memcmp_const_size_no_update_deref2(
-; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(16) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
+; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(40) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
; CHECK-NEXT: ret i32 [[CALL]]
;
%call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)