Merge pull request #10684 from ethereum/fixIRWrappingExp

Use wrapping arithmetic for exp in unchecked blocks.
This commit is contained in:
Harikrishnan Mulackal
2021-01-06 18:53:54 +01:00
committed by GitHub
7 changed files with 18 additions and 2 deletions
@@ -802,7 +802,12 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
IRVariable left = convert(_binOp.leftExpression(), *commonType);
IRVariable right = convert(_binOp.rightExpression(), *type(_binOp.rightExpression()).mobileType());
if (auto rationalNumberType = dynamic_cast<RationalNumberType const*>(_binOp.leftExpression().annotation().type))
if (m_context.arithmetic() == Arithmetic::Wrapping)
define(_binOp) << m_utils.wrappingIntExpFunction(
dynamic_cast<IntegerType const&>(left.type()),
dynamic_cast<IntegerType const&>(right.type())
) << "(" << left.name() << ", " << right.name() << ")\n";
else if (auto rationalNumberType = dynamic_cast<RationalNumberType const*>(_binOp.leftExpression().annotation().type))
{
solAssert(rationalNumberType->integerType(), "Invalid literal as the base for exponentiation.");
solAssert(dynamic_cast<IntegerType const*>(commonType), "");
@@ -818,7 +823,6 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
dynamic_cast<IntegerType const&>(left.type()),
dynamic_cast<IntegerType const&>(right.type())
) << "(" << left.name() << ", " << right.name() << ")\n";
}
else if (TokenTraits::isShiftOp(op))
{
@@ -7,5 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1
@@ -6,5 +6,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1
@@ -7,5 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1
@@ -9,5 +9,7 @@ contract C {
}
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x00
@@ -7,6 +7,8 @@ contract test {
}
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 0 -> 1, 1
// f(uint256): 1 -> 2, -2
@@ -10,5 +10,7 @@ contract test {
return r;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 4