From 59a65f7b24350cf483d777acfb403e9b8a31a771 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Tue, 25 Dec 2012 16:04:38 +0000 Subject: [PATCH] [msan] Fix handling of vectors of pointers. VectorType::getInteger() can not be used with them, because pointer size depends on the target. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171070 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/MemorySanitizer.cpp | 9 +++++++-- .../Instrumentation/MemorySanitizer/msan_basic.ll | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index ba16e3dc3f7..41e250b7e73 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -541,8 +541,11 @@ struct MemorySanitizerVisitor : public InstVisitor { // This may return weird-sized types like i1. if (IntegerType *IT = dyn_cast(OrigTy)) return IT; - if (VectorType *VT = dyn_cast(OrigTy)) - return VectorType::getInteger(VT); + if (VectorType *VT = dyn_cast(OrigTy)) { + uint32_t EltSize = MS.TD->getTypeStoreSizeInBits(VT->getElementType()); + return VectorType::get(IntegerType::get(*MS.C, EltSize), + VT->getNumElements()); + } if (StructType *ST = dyn_cast(OrigTy)) { SmallVector Elements; for (unsigned i = 0, n = ST->getNumElements(); i < n; i++) @@ -1023,6 +1026,8 @@ struct MemorySanitizerVisitor : public InstVisitor { } size_t VectorOrPrimitiveTypeSizeInBits(Type *Ty) { + assert(!(Ty->isVectorTy() && Ty->getScalarType()->isPointerTy()) && + "Vector of pointers is not a valid shadow type"); return Ty->isVectorTy() ? Ty->getVectorNumElements() * Ty->getScalarSizeInBits() : Ty->getPrimitiveSizeInBits(); diff --git a/test/Instrumentation/MemorySanitizer/msan_basic.ll b/test/Instrumentation/MemorySanitizer/msan_basic.ll index 3237e91db70..cd203299336 100644 --- a/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ b/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -512,3 +512,18 @@ declare <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %a, <8 x i16> %b) nounwind ; CHECK-ORIGINS: call <8 x i16> @llvm.x86.sse2.padds.w ; CHECK-ORIGINS: store i32 {{.*}} @__msan_retval_origin_tls ; CHECK-ORIGINS: ret <8 x i16> + + +; Test handling of vectors of pointers. +; Check that shadow of such vector is a vector of integers. + +define <8 x i8*> @VectorOfPointers(<8 x i8*>* %p) nounwind uwtable { + %x = load <8 x i8*>* %p + ret <8 x i8*> %x +} + +; CHECK: @VectorOfPointers +; CHECK: load <8 x i64>* +; CHECK: load <8 x i8*>* +; CHECK: store <8 x i64> {{.*}} @__msan_retval_tls +; CHECK: ret <8 x i8*>