forked from OSchip/llvm-project
[msan] Fix crash on multiplication by a non-integer constant.
Fixes PR25160. llvm-svn: 250260
This commit is contained in:
parent
5cb86d5a40
commit
ebd3f44f93
|
@ -1617,18 +1617,24 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
Type *EltTy = Ty->getSequentialElementType();
|
||||
SmallVector<Constant *, 16> Elements;
|
||||
for (unsigned Idx = 0; Idx < NumElements; ++Idx) {
|
||||
ConstantInt *Elt =
|
||||
dyn_cast<ConstantInt>(ConstArg->getAggregateElement(Idx));
|
||||
APInt V = Elt->getValue();
|
||||
APInt V2 = APInt(V.getBitWidth(), 1) << V.countTrailingZeros();
|
||||
Elements.push_back(ConstantInt::get(EltTy, V2));
|
||||
if (ConstantInt *Elt =
|
||||
dyn_cast<ConstantInt>(ConstArg->getAggregateElement(Idx))) {
|
||||
APInt V = Elt->getValue();
|
||||
APInt V2 = APInt(V.getBitWidth(), 1) << V.countTrailingZeros();
|
||||
Elements.push_back(ConstantInt::get(EltTy, V2));
|
||||
} else {
|
||||
Elements.push_back(ConstantInt::get(EltTy, 1));
|
||||
}
|
||||
}
|
||||
ShadowMul = ConstantVector::get(Elements);
|
||||
} else {
|
||||
ConstantInt *Elt = dyn_cast<ConstantInt>(ConstArg);
|
||||
APInt V = Elt->getValue();
|
||||
APInt V2 = APInt(V.getBitWidth(), 1) << V.countTrailingZeros();
|
||||
ShadowMul = ConstantInt::get(Elt->getType(), V2);
|
||||
if (ConstantInt *Elt = dyn_cast<ConstantInt>(ConstArg)) {
|
||||
APInt V = Elt->getValue();
|
||||
APInt V2 = APInt(V.getBitWidth(), 1) << V.countTrailingZeros();
|
||||
ShadowMul = ConstantInt::get(Ty, V2);
|
||||
} else {
|
||||
ShadowMul = ConstantInt::get(Ty, 1);
|
||||
}
|
||||
}
|
||||
|
||||
IRBuilder<> IRB(&I);
|
||||
|
|
|
@ -92,3 +92,26 @@ entry:
|
|||
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
|
||||
; CHECK: [[B:%.*]] = mul <4 x i32> [[A]], <i32 1024, i32 0, i32 16, i32 16>
|
||||
; CHECK: store <4 x i32> [[B]], <4 x i32>* {{.*}} @__msan_retval_tls
|
||||
|
||||
|
||||
; The constant in multiplication does not have to be a literal integer constant.
|
||||
@X = linkonce_odr global i8* null
|
||||
define i64 @MulNonIntegerConst(i64 %a) sanitize_memory {
|
||||
%mul = mul i64 %a, ptrtoint (i8** @X to i64)
|
||||
ret i64 %mul
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @MulNonIntegerConst(
|
||||
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
|
||||
; CHECK: [[B:%.*]] = mul i64 [[A]], 1
|
||||
; CHECK: store i64 [[B]], {{.*}}@__msan_retval_tls
|
||||
|
||||
define <2 x i64> @MulNonIntegerVectorConst(<2 x i64> %a) sanitize_memory {
|
||||
%mul = mul <2 x i64> %a, <i64 3072, i64 ptrtoint (i8** @X to i64)>
|
||||
ret <2 x i64> %mul
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @MulNonIntegerVectorConst(
|
||||
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
|
||||
; CHECK: [[B:%.*]] = mul <2 x i64> [[A]], <i64 1024, i64 1>
|
||||
; CHECK: store <2 x i64> [[B]], {{.*}}@__msan_retval_tls
|
||||
|
|
Loading…
Reference in New Issue