[hwasan] [nfc] simplify getAllocaSizeInBytes
authorFlorian Mayer <fmayer@google.com>
Fri, 4 Feb 2022 01:42:19 +0000 (17:42 -0800)
committerFlorian Mayer <fmayer@google.com>
Fri, 4 Feb 2022 01:59:24 +0000 (17:59 -0800)
AllocaInst::getAllocationSize implements essentially the same logic as
our custom function.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D118958

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

index b7f6487..09930ca 100644 (file)
@@ -1057,15 +1057,8 @@ bool HWAddressSanitizer::instrumentMemAccess(InterestingMemoryOperand &O) {
 }
 
 static uint64_t getAllocaSizeInBytes(const AllocaInst &AI) {
-  uint64_t ArraySize = 1;
-  if (AI.isArrayAllocation()) {
-    const ConstantInt *CI = dyn_cast<ConstantInt>(AI.getArraySize());
-    assert(CI && "non-constant array size");
-    ArraySize = CI->getZExtValue();
-  }
-  Type *Ty = AI.getAllocatedType();
-  uint64_t SizeInBytes = AI.getModule()->getDataLayout().getTypeAllocSize(Ty);
-  return SizeInBytes * ArraySize;
+  auto DL = AI.getModule()->getDataLayout();
+  return AI.getAllocationSizeInBits(DL).getValue() / 8;
 }
 
 void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag,