mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Checked arithmetic by default.
This commit is contained in:
@@ -474,6 +474,25 @@ bool IRGeneratorForStatements::visit(TupleExpression const& _tuple)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
{
|
||||
solAssert(m_context.arithmetic() == Arithmetic::Checked, "");
|
||||
m_context.setArithmetic(Arithmetic::Wrapping);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void IRGeneratorForStatements::endVisit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
{
|
||||
solAssert(m_context.arithmetic() == Arithmetic::Wrapping, "");
|
||||
m_context.setArithmetic(Arithmetic::Checked);
|
||||
}
|
||||
}
|
||||
|
||||
bool IRGeneratorForStatements::visit(IfStatement const& _ifStatement)
|
||||
{
|
||||
_ifStatement.condition().accept(*this);
|
||||
@@ -618,11 +637,11 @@ void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
|
||||
else if (op == Token::Sub)
|
||||
{
|
||||
IntegerType const& intType = *dynamic_cast<IntegerType const*>(&resultType);
|
||||
define(_unaryOperation) <<
|
||||
m_utils.negateNumberCheckedFunction(intType) <<
|
||||
"(" <<
|
||||
IRVariable(_unaryOperation.subExpression()).name() <<
|
||||
")\n";
|
||||
define(_unaryOperation) << (
|
||||
m_context.arithmetic() == Arithmetic::Checked ?
|
||||
m_utils.negateNumberCheckedFunction(intType) :
|
||||
m_utils.negateNumberWrappingFunction(intType)
|
||||
) << "(" << IRVariable(_unaryOperation.subExpression()).name() << ")\n";
|
||||
}
|
||||
else
|
||||
solUnimplementedAssert(false, "Unary operator not yet implemented");
|
||||
@@ -2560,23 +2579,23 @@ string IRGeneratorForStatements::binaryOperation(
|
||||
if (IntegerType const* type = dynamic_cast<IntegerType const*>(&_type))
|
||||
{
|
||||
string fun;
|
||||
// TODO: Implement all operations for signed and unsigned types.
|
||||
bool checked = m_context.arithmetic() == Arithmetic::Checked;
|
||||
switch (_operator)
|
||||
{
|
||||
case Token::Add:
|
||||
fun = m_utils.overflowCheckedIntAddFunction(*type);
|
||||
fun = checked ? m_utils.overflowCheckedIntAddFunction(*type) : m_utils.wrappingIntAddFunction(*type);
|
||||
break;
|
||||
case Token::Sub:
|
||||
fun = m_utils.overflowCheckedIntSubFunction(*type);
|
||||
fun = checked ? m_utils.overflowCheckedIntSubFunction(*type) : m_utils.wrappingIntSubFunction(*type);
|
||||
break;
|
||||
case Token::Mul:
|
||||
fun = m_utils.overflowCheckedIntMulFunction(*type);
|
||||
fun = checked ? m_utils.overflowCheckedIntMulFunction(*type) : m_utils.wrappingIntMulFunction(*type);
|
||||
break;
|
||||
case Token::Div:
|
||||
fun = m_utils.overflowCheckedIntDivFunction(*type);
|
||||
fun = checked ? m_utils.overflowCheckedIntDivFunction(*type) : m_utils.wrappingIntDivFunction(*type);
|
||||
break;
|
||||
case Token::Mod:
|
||||
fun = m_utils.checkedIntModFunction(*type);
|
||||
fun = m_utils.intModFunction(*type);
|
||||
break;
|
||||
case Token::BitOr:
|
||||
fun = "or";
|
||||
|
||||
Reference in New Issue
Block a user