diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index d7a3680c9..884edb1bd 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -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(_binOp.leftExpression().annotation().type)) + if (m_context.arithmetic() == Arithmetic::Wrapping) + define(_binOp) << m_utils.wrappingIntExpFunction( + dynamic_cast(left.type()), + dynamic_cast(right.type()) + ) << "(" << left.name() << ", " << right.name() << ")\n"; + else if (auto rationalNumberType = dynamic_cast(_binOp.leftExpression().annotation().type)) { solAssert(rationalNumberType->integerType(), "Invalid literal as the base for exponentiation."); solAssert(dynamic_cast(commonType), ""); @@ -818,7 +823,6 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp) dynamic_cast(left.type()), dynamic_cast(right.type()) ) << "(" << left.name() << ", " << right.name() << ")\n"; - } else if (TokenTraits::isShiftOp(op)) { diff --git a/test/libsolidity/semanticTests/cleanup/exp_cleanup.sol b/test/libsolidity/semanticTests/cleanup/exp_cleanup.sol index 103de86cc..925d7e9d6 100644 --- a/test/libsolidity/semanticTests/cleanup/exp_cleanup.sol +++ b/test/libsolidity/semanticTests/cleanup/exp_cleanup.sol @@ -7,5 +7,7 @@ contract C { } } +// ==== +// compileViaYul: also // ---- // f() -> 0x1 diff --git a/test/libsolidity/semanticTests/cleanup/exp_cleanup_direct.sol b/test/libsolidity/semanticTests/cleanup/exp_cleanup_direct.sol index 78221939e..542b399be 100644 --- a/test/libsolidity/semanticTests/cleanup/exp_cleanup_direct.sol +++ b/test/libsolidity/semanticTests/cleanup/exp_cleanup_direct.sol @@ -6,5 +6,7 @@ contract C { } } +// ==== +// compileViaYul: also // ---- // f() -> 0x1 diff --git a/test/libsolidity/semanticTests/cleanup/exp_cleanup_nonzero_base.sol b/test/libsolidity/semanticTests/cleanup/exp_cleanup_nonzero_base.sol index 5ecc1114e..976018a48 100644 --- a/test/libsolidity/semanticTests/cleanup/exp_cleanup_nonzero_base.sol +++ b/test/libsolidity/semanticTests/cleanup/exp_cleanup_nonzero_base.sol @@ -7,5 +7,7 @@ contract C { } } +// ==== +// compileViaYul: also // ---- // f() -> 0x1 diff --git a/test/libsolidity/semanticTests/cleanup/exp_cleanup_smaller_base.sol b/test/libsolidity/semanticTests/cleanup/exp_cleanup_smaller_base.sol index 7b81d0a1c..ca8c94372 100644 --- a/test/libsolidity/semanticTests/cleanup/exp_cleanup_smaller_base.sol +++ b/test/libsolidity/semanticTests/cleanup/exp_cleanup_smaller_base.sol @@ -9,5 +9,7 @@ contract C { } } } +// ==== +// compileViaYul: also // ---- // f() -> 0x00 diff --git a/test/libsolidity/semanticTests/exponentiation/literal_base.sol b/test/libsolidity/semanticTests/exponentiation/literal_base.sol index 3dcba494a..255a22eb8 100644 --- a/test/libsolidity/semanticTests/exponentiation/literal_base.sol +++ b/test/libsolidity/semanticTests/exponentiation/literal_base.sol @@ -7,6 +7,8 @@ contract test { } } } +// ==== +// compileViaYul: also // ---- // f(uint256): 0 -> 1, 1 // f(uint256): 1 -> 2, -2 diff --git a/test/libsolidity/semanticTests/exponentiation/small_exp.sol b/test/libsolidity/semanticTests/exponentiation/small_exp.sol index a26675fb7..7f8d1d224 100644 --- a/test/libsolidity/semanticTests/exponentiation/small_exp.sol +++ b/test/libsolidity/semanticTests/exponentiation/small_exp.sol @@ -10,5 +10,7 @@ contract test { return r; } } +// ==== +// compileViaYul: also // ---- // f() -> 4