summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-07-16 03:25:50 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2019-07-16 03:25:50 +0000
commite5c4b468f06307bc1b8341af9ccf9dd69fa890f4 (patch)
tree9067ec049e3e318c138dad454cad80ba0efa9bf2 /llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
parenta17b1aed6ab205515adc31d19e953635e563e5c4 (diff)
downloadbcm5719-llvm-e5c4b468f06307bc1b8341af9ccf9dd69fa890f4.tar.gz
bcm5719-llvm-e5c4b468f06307bc1b8341af9ccf9dd69fa890f4.zip
hwasan: Pad arrays with non-1 size correctly.
Spotted by eugenis. Differential Revision: https://reviews.llvm.org/D64783 llvm-svn: 366171
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index a961c813587..450ae2f7902 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1108,8 +1108,14 @@ bool HWAddressSanitizer::sanitizeFunction(Function &F) {
uint64_t AlignedSize = alignTo(Size, Mapping.getAllocaAlignment());
AI->setAlignment(std::max(AI->getAlignment(), 16u));
if (Size != AlignedSize) {
+ Type *AllocatedType = AI->getAllocatedType();
+ if (AI->isArrayAllocation()) {
+ uint64_t ArraySize =
+ cast<ConstantInt>(AI->getArraySize())->getZExtValue();
+ AllocatedType = ArrayType::get(AllocatedType, ArraySize);
+ }
Type *TypeWithPadding = StructType::get(
- AI->getAllocatedType(), ArrayType::get(Int8Ty, AlignedSize - Size));
+ AllocatedType, ArrayType::get(Int8Ty, AlignedSize - Size));
auto *NewAI = new AllocaInst(
TypeWithPadding, AI->getType()->getAddressSpace(), nullptr, "", AI);
NewAI->takeName(AI);
@@ -1117,10 +1123,8 @@ bool HWAddressSanitizer::sanitizeFunction(Function &F) {
NewAI->setUsedWithInAlloca(AI->isUsedWithInAlloca());
NewAI->setSwiftError(AI->isSwiftError());
NewAI->copyMetadata(*AI);
- Value *Zero = ConstantInt::get(Int32Ty, 0);
- auto *GEP = GetElementPtrInst::Create(TypeWithPadding, NewAI,
- {Zero, Zero}, "", AI);
- AI->replaceAllUsesWith(GEP);
+ auto *Bitcast = new BitCastInst(NewAI, AI->getType(), "", AI);
+ AI->replaceAllUsesWith(Bitcast);
AllocaToPaddedAllocaMap[AI] = NewAI;
}
}
OpenPOWER on IntegriCloud