mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use wrapping arithmetic for exp in unchecked blocks.
This commit is contained in:
parent
6bcae84610
commit
2ab83217e3
@ -802,7 +802,12 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
|
|||||||
IRVariable left = convert(_binOp.leftExpression(), *commonType);
|
IRVariable left = convert(_binOp.leftExpression(), *commonType);
|
||||||
IRVariable right = convert(_binOp.rightExpression(), *type(_binOp.rightExpression()).mobileType());
|
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(rationalNumberType->integerType(), "Invalid literal as the base for exponentiation.");
|
||||||
solAssert(dynamic_cast<IntegerType const*>(commonType), "");
|
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&>(left.type()),
|
||||||
dynamic_cast<IntegerType const&>(right.type())
|
dynamic_cast<IntegerType const&>(right.type())
|
||||||
) << "(" << left.name() << ", " << right.name() << ")\n";
|
) << "(" << left.name() << ", " << right.name() << ")\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (TokenTraits::isShiftOp(op))
|
else if (TokenTraits::isShiftOp(op))
|
||||||
{
|
{
|
||||||
|
@ -7,5 +7,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 0x1
|
// f() -> 0x1
|
||||||
|
@ -6,5 +6,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 0x1
|
// f() -> 0x1
|
||||||
|
@ -7,5 +7,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 0x1
|
// f() -> 0x1
|
||||||
|
@ -9,5 +9,7 @@ contract C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 0x00
|
// f() -> 0x00
|
||||||
|
@ -7,6 +7,8 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f(uint256): 0 -> 1, 1
|
// f(uint256): 0 -> 1, 1
|
||||||
// f(uint256): 1 -> 2, -2
|
// f(uint256): 1 -> 2, -2
|
||||||
|
@ -10,5 +10,7 @@ contract test {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 4
|
// f() -> 4
|
||||||
|
Loading…
Reference in New Issue
Block a user