forked from OSchip/llvm-project
[asan-asm-instrumentation] Follow-up fixes to r219602: asserts are moved into
function. llvm-svn: 219610
This commit is contained in:
parent
3f840a934e
commit
ab1b88ab59
|
@ -39,14 +39,14 @@ static cl::opt<bool> ClAsanInstrumentAssembly(
|
||||||
const int64_t MinAllowedDisplacement = std::numeric_limits<int32_t>::min();
|
const int64_t MinAllowedDisplacement = std::numeric_limits<int32_t>::min();
|
||||||
const int64_t MaxAllowedDisplacement = std::numeric_limits<int32_t>::max();
|
const int64_t MaxAllowedDisplacement = std::numeric_limits<int32_t>::max();
|
||||||
|
|
||||||
int64_t ApplyBounds(int64_t Displacement) {
|
int64_t ApplyDisplacementBounds(int64_t Displacement) {
|
||||||
return std::max(std::min(MaxAllowedDisplacement, Displacement),
|
return std::max(std::min(MaxAllowedDisplacement, Displacement),
|
||||||
MinAllowedDisplacement);
|
MinAllowedDisplacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InBounds(int64_t Displacement) {
|
void CheckDisplacementBounds(int64_t Displacement) {
|
||||||
return Displacement >= MinAllowedDisplacement &&
|
assert(Displacement >= MinAllowedDisplacement &&
|
||||||
Displacement <= MaxAllowedDisplacement;
|
Displacement <= MaxAllowedDisplacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsStackReg(unsigned Reg) { return Reg == X86::RSP || Reg == X86::ESP; }
|
bool IsStackReg(unsigned Reg) { return Reg == X86::RSP || Reg == X86::ESP; }
|
||||||
|
@ -339,7 +339,7 @@ void X86AddressSanitizer::ComputeMemOperandAddress(X86Operand &Op,
|
||||||
|
|
||||||
while (Residue != 0) {
|
while (Residue != 0) {
|
||||||
const MCConstantExpr *Disp =
|
const MCConstantExpr *Disp =
|
||||||
MCConstantExpr::Create(ApplyBounds(Residue), Ctx);
|
MCConstantExpr::Create(ApplyDisplacementBounds(Residue), Ctx);
|
||||||
std::unique_ptr<X86Operand> DispOp =
|
std::unique_ptr<X86Operand> DispOp =
|
||||||
X86Operand::CreateMem(0, Disp, Reg, 0, 1, SMLoc(), SMLoc());
|
X86Operand::CreateMem(0, Disp, Reg, 0, 1, SMLoc(), SMLoc());
|
||||||
EmitLEA(*DispOp, VT, Reg, Out);
|
EmitLEA(*DispOp, VT, Reg, Out);
|
||||||
|
@ -362,11 +362,11 @@ X86AddressSanitizer::AddDisplacement(X86Operand &Op, int64_t Displacement,
|
||||||
|
|
||||||
int64_t OrigDisplacement =
|
int64_t OrigDisplacement =
|
||||||
static_cast<const MCConstantExpr *>(Op.getMemDisp())->getValue();
|
static_cast<const MCConstantExpr *>(Op.getMemDisp())->getValue();
|
||||||
assert(InBounds(OrigDisplacement));
|
CheckDisplacementBounds(OrigDisplacement);
|
||||||
Displacement += OrigDisplacement;
|
Displacement += OrigDisplacement;
|
||||||
|
|
||||||
int64_t NewDisplacement = ApplyBounds(Displacement);
|
int64_t NewDisplacement = ApplyDisplacementBounds(Displacement);
|
||||||
assert(InBounds(NewDisplacement));
|
CheckDisplacementBounds(NewDisplacement);
|
||||||
|
|
||||||
*Residue = Displacement - NewDisplacement;
|
*Residue = Displacement - NewDisplacement;
|
||||||
const MCExpr *Disp = MCConstantExpr::Create(NewDisplacement, Ctx);
|
const MCExpr *Disp = MCConstantExpr::Create(NewDisplacement, Ctx);
|
||||||
|
|
Loading…
Reference in New Issue