[MSan][OpaquePtr] Use inline asm elementtype instead of getPointerElementType()

This commit is contained in:
Arthur Eubanks 2022-02-11 11:50:11 -08:00
parent 11b0506c08
commit b59a402237
2 changed files with 18 additions and 7 deletions

View File

@ -1779,6 +1779,15 @@ public:
return nullptr;
}
/// Extract the elementtype type for a call or parameter.
Type *getParamElementType(unsigned ArgNo) const {
if (auto *Ty = Attrs.getParamElementType(ArgNo))
return Ty;
if (const Function *F = getCalledFunction())
return F->getAttributes().getParamElementType(ArgNo);
return nullptr;
}
/// Extract the number of dereferenceable bytes for a call or
/// parameter (0=unknown).
uint64_t getRetDereferenceableBytes() const {

View File

@ -4083,8 +4083,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
// Nothing to do here.
}
void instrumentAsmArgument(Value *Operand, Instruction &I, IRBuilder<> &IRB,
const DataLayout &DL, bool isOutput) {
void instrumentAsmArgument(Value *Operand, Type *ElemTy, Instruction &I,
IRBuilder<> &IRB, const DataLayout &DL,
bool isOutput) {
// For each assembly argument, we check its value for being initialized.
// If the argument is a pointer, we assume it points to a single element
// of the corresponding type (or to a 8-byte word, if the type is unsized).
@ -4096,10 +4097,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
assert(!isOutput);
return;
}
Type *ElType = OpType->getPointerElementType();
if (!ElType->isSized())
if (!ElemTy->isSized())
return;
int Size = DL.getTypeStoreSize(ElType);
int Size = DL.getTypeStoreSize(ElemTy);
Value *Ptr = IRB.CreatePointerCast(Operand, IRB.getInt8PtrTy());
Value *SizeVal = ConstantInt::get(MS.IntptrTy, Size);
IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Ptr, SizeVal});
@ -4159,14 +4159,16 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
// that we won't overwrite uninit values before checking them.
for (int i = OutputArgs; i < NumOperands; i++) {
Value *Operand = CB->getOperand(i);
instrumentAsmArgument(Operand, I, IRB, DL, /*isOutput*/ false);
instrumentAsmArgument(Operand, CB->getParamElementType(i), I, IRB, DL,
/*isOutput*/ false);
}
// Unpoison output arguments. This must happen before the actual InlineAsm
// call, so that the shadow for memory published in the asm() statement
// remains valid.
for (int i = 0; i < OutputArgs; i++) {
Value *Operand = CB->getOperand(i);
instrumentAsmArgument(Operand, I, IRB, DL, /*isOutput*/ true);
instrumentAsmArgument(Operand, CB->getParamElementType(i), I, IRB, DL,
/*isOutput*/ true);
}
setShadow(&I, getCleanShadow(&I));