From 47a0e9f49b903aa4ef821d2c7a679a145ee983f9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 18 May 2020 21:50:15 +0200 Subject: [PATCH] [Sanitizers] Use getParamByValType() (NFC) Instead of fetching the pointer element type. --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 2 +- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 0fbc4d5..816b8b1 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2901,7 +2901,7 @@ void FunctionStackPoisoner::copyArgsPassedByValToAllocas() { const DataLayout &DL = F.getParent()->getDataLayout(); for (Argument &Arg : F.args()) { if (Arg.hasByValAttr()) { - Type *Ty = Arg.getType()->getPointerElementType(); + Type *Ty = Arg.getParamByValType(); const Align Alignment = DL.getValueOrABITypeAlignment(Arg.getParamAlign(), Ty); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index ddfe27b..53661b5 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1637,7 +1637,7 @@ struct MemorySanitizerVisitor : public InstVisitor { } unsigned Size = FArg.hasByValAttr() - ? DL.getTypeAllocSize(FArg.getType()->getPointerElementType()) + ? DL.getTypeAllocSize(FArg.getParamByValType()) : DL.getTypeAllocSize(FArg.getType()); if (A == &FArg) { bool Overflow = ArgOffset + Size > kParamTLSSize; @@ -1647,8 +1647,7 @@ struct MemorySanitizerVisitor : public InstVisitor { // argument shadow to the underlying memory. // Figure out maximal valid memcpy alignment. const Align ArgAlign = DL.getValueOrABITypeAlignment( - MaybeAlign(FArg.getParamAlignment()), - A->getType()->getPointerElementType()); + MaybeAlign(FArg.getParamAlignment()), FArg.getParamByValType()); Value *CpShadowPtr = getShadowOriginPtr(V, EntryIRB, EntryIRB.getInt8Ty(), ArgAlign, /*isStore*/ true) @@ -3378,7 +3377,7 @@ struct MemorySanitizerVisitor : public InstVisitor { if (CB.paramHasAttr(i, Attribute::ByVal)) { assert(A->getType()->isPointerTy() && "ByVal argument is not a pointer!"); - Size = DL.getTypeAllocSize(A->getType()->getPointerElementType()); + Size = DL.getTypeAllocSize(CB.getParamByValType(i)); if (ArgOffset + Size > kParamTLSSize) break; const MaybeAlign ParamAlignment(CB.getParamAlign(i)); MaybeAlign Alignment = llvm::None; @@ -3874,7 +3873,7 @@ struct VarArgAMD64Helper : public VarArgHelper { if (IsFixed) continue; assert(A->getType()->isPointerTy()); - Type *RealTy = A->getType()->getPointerElementType(); + Type *RealTy = CB.getParamByValType(ArgNo); uint64_t ArgSize = DL.getTypeAllocSize(RealTy); Value *ShadowBase = getShadowPtrForVAArgument( RealTy, IRB, OverflowOffset, alignTo(ArgSize, 8)); @@ -4491,7 +4490,7 @@ struct VarArgPowerPC64Helper : public VarArgHelper { bool IsByVal = CB.paramHasAttr(ArgNo, Attribute::ByVal); if (IsByVal) { assert(A->getType()->isPointerTy()); - Type *RealTy = A->getType()->getPointerElementType(); + Type *RealTy = CB.getParamByValType(ArgNo); uint64_t ArgSize = DL.getTypeAllocSize(RealTy); MaybeAlign ArgAlign = CB.getParamAlign(ArgNo); if (!ArgAlign || *ArgAlign < Align(8)) -- 2.7.4