ASan: use getTypeAllocSize instead of getTypeStoreSize.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 2 Mar 2012 10:41:08 +0000 (10:41 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 2 Mar 2012 10:41:08 +0000 (10:41 +0000)
This change replaces getTypeStoreSize with getTypeAllocSize in AddressSanitizer
instrumentation for stack allocations.

One case where old behaviour produced undesired results is an optimization in
InstCombine pass (PromoteCastOfAllocation), which can replace  alloca(T) with
alloca(S), where S has the same AllocSize, but a smaller StoreSize. Another
case is memcpy(long double => long double), where ASan will poison bytes 10-15
of a stack-allocated long double (StoreSize  10, AllocSize 16,
sizeof(long double) = 16).

See http://llvm.org/bugs/show_bug.cgi?id=12047 for more context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151887 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp

index ce5d43a68fce9a52cd12977a1c70f80bca46a6fc..123e39904231a4ebe00b96a4bd00dca0384c7d4b 100644 (file)
@@ -167,7 +167,7 @@ struct AddressSanitizer : public ModulePass {
 
   uint64_t getAllocaSizeInBytes(AllocaInst *AI) {
     Type *Ty = AI->getAllocatedType();
 
   uint64_t getAllocaSizeInBytes(AllocaInst *AI) {
     Type *Ty = AI->getAllocatedType();
-    uint64_t SizeInBytes = TD->getTypeStoreSizeInBits(Ty) / 8;
+    uint64_t SizeInBytes = TD->getTypeAllocSize(Ty);
     return SizeInBytes;
   }
   uint64_t getAlignedSize(uint64_t SizeInBytes) {
     return SizeInBytes;
   }
   uint64_t getAlignedSize(uint64_t SizeInBytes) {