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
commit 5241b7b761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 2 deletions

View File

@ -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))
{

View File

@ -7,5 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1

View File

@ -6,5 +6,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1

View File

@ -7,5 +7,7 @@ contract C {
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x1

View File

@ -9,5 +9,7 @@ contract C {
}
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x00

View File

@ -7,6 +7,8 @@ contract test {
}
}
}
// ====
// compileViaYul: also
// ----
// f(uint256): 0 -> 1, 1
// f(uint256): 1 -> 2, -2

View File

@ -10,5 +10,7 @@ contract test {
return r;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 4