diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp --- a/llvm/lib/Analysis/MemoryLocation.cpp +++ b/llvm/lib/Analysis/MemoryLocation.cpp @@ -253,12 +253,17 @@ assert((ArgIdx == 0 || ArgIdx == 1) && "Invalid argument index for str function"); return MemoryLocation::getAfter(Arg, AATags); - case LibFunc_memset_chk: { + case LibFunc_memset_chk: assert(ArgIdx == 0 && "Invalid argument index for memset_chk"); + LLVM_FALLTHROUGH; + case LibFunc_memcpy_chk: { + assert((ArgIdx == 0 || ArgIdx == 1) && + "Invalid argument index for memcpy_chk"); LocationSize Size = LocationSize::afterPointer(); if (const auto *Len = dyn_cast(Call->getArgOperand(2))) { - // memset_chk writes at most Len bytes. It may write less, if Len - // exceeds the specified max size and aborts. + // memset_chk writes at most Len bytes, memcpy_chk reads/writes at most + // Len bytes. They may read/write less, if Len exceeds the specified max + // size and aborts. Size = LocationSize::upperBound(Len->getZExtValue()); } return MemoryLocation(Arg, Size, AATags); diff --git a/llvm/test/Analysis/BasicAA/libfuncs.ll b/llvm/test/Analysis/BasicAA/libfuncs.ll --- a/llvm/test/Analysis/BasicAA/libfuncs.ll +++ b/llvm/test/Analysis/BasicAA/libfuncs.ll @@ -323,9 +323,9 @@ ; CHECK: Just Mod: Ptr: i8* %a <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) ; CHECK-NEXT: Just Mod: Ptr: i8* %res <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) ; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.1 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) -; CHECK-NEXT: Just Mod: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) +; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) ; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) -; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) +; CHECK-NEXT: NoModRef: Ptr: i8* %b.gep.5 <-> %res = tail call i8* @__memcpy_chk(i8* %a, i8* %b, i64 4, i64 %n) ; entry: load i8, i8* %a