Skip to content

Commit 374f5f0

Browse files
committed
[hwasan] [nfc] simplify getAllocaSizeInBytes
AllocaInst::getAllocationSize implements essentially the same logic as our custom function. Reviewed By: hctim Differential Revision: https://reviews.llvm.org/D118958
1 parent 8cc4ca9 commit 374f5f0

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,15 +1057,8 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
10571057
}
10581058

10591059
static uint64_t getAllocaSizeInBytes(const AllocaInst &AI) {
1060-
uint64_t ArraySize = 1;
1061-
if (AI.isArrayAllocation()) {
1062-
const ConstantInt *CI = dyn_cast<ConstantInt>(AI.getArraySize());
1063-
assert(CI && "non-constant array size");
1064-
ArraySize = CI->getZExtValue();
1065-
}
1066-
Type *Ty = AI.getAllocatedType();
1067-
uint64_t SizeInBytes = AI.getModule()->getDataLayout().getTypeAllocSize(Ty);
1068-
return SizeInBytes * ArraySize;
1060+
auto DL = AI.getModule()->getDataLayout();
1061+
return AI.getAllocationSizeInBits(DL).getValue() / 8;
10691062
}
10701063

10711064
void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag,

0 commit comments

Comments
 (0)