diff options
author | Florian Hahn <flo@fhahn.com> | 2021-12-02 14:18:04 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2021-12-02 14:18:05 +0000 |
commit | 639a78a4bf9da0a03dcd12c27f625a134a3ee6cc (patch) | |
tree | 0ef7bd1ee41e74a2f084836387566e2c4e27af81 /llvm/lib/Analysis/MemoryLocation.cpp | |
parent | 32568fc95e75b9c6cfaf6964bcf2d8db342f23ad (diff) | |
download | llvm-639a78a4bf9da0a03dcd12c27f625a134a3ee6cc.zip llvm-639a78a4bf9da0a03dcd12c27f625a134a3ee6cc.tar.gz llvm-639a78a4bf9da0a03dcd12c27f625a134a3ee6cc.tar.bz2 |
[MemoryLocation] Support strncpy in getForArgument.
The size argument of strncpy can be used as bound for the size of
its pointer arguments.
strncpy is guaranteed to write N bytes and reads up to N bytes.
Reviewed By: xbolva00
Differential Revision: https://reviews.llvm.org/D114871
Diffstat (limited to 'llvm/lib/Analysis/MemoryLocation.cpp')
-rw-r--r-- | llvm/lib/Analysis/MemoryLocation.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp index b4eb06d..854ba83 100644 --- a/llvm/lib/Analysis/MemoryLocation.cpp +++ b/llvm/lib/Analysis/MemoryLocation.cpp @@ -223,6 +223,18 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call, } return MemoryLocation(Arg, Size, AATags); } + case LibFunc_strncpy: { + assert((ArgIdx == 0 || ArgIdx == 1) && + "Invalid argument index for strncpy"); + LocationSize Size = LocationSize::afterPointer(); + if (const auto *Len = dyn_cast<ConstantInt>(Call->getArgOperand(2))) { + // strncpy is guaranteed to write Len bytes, but only reads up to Len + // bytes. + Size = ArgIdx == 0 ? LocationSize::precise(Len->getZExtValue()) + : LocationSize::upperBound(Len->getZExtValue()); + } + return MemoryLocation(Arg, Size, AATags); + } case LibFunc_memset_pattern16: assert((ArgIdx == 0 || ArgIdx == 1) && "Invalid argument index for memset_pattern16"); |