[llvm] 374f5f0 - [hwasan] [nfc] simplify getAllocaSizeInBytes

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 17:59:35 PST 2022


Author: Florian Mayer
Date: 2022-02-03T17:59:24-08:00
New Revision: 374f5f0df432a2ebeccffa1ec972920d195ddcbe

URL: https://github.com/llvm/llvm-project/commit/374f5f0df432a2ebeccffa1ec972920d195ddcbe
DIFF: https://github.com/llvm/llvm-project/commit/374f5f0df432a2ebeccffa1ec972920d195ddcbe.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index b7f64875ec9b5..09930ca64ad60 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -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,


        


More information about the llvm-commits mailing list