diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index c26012e17..1efc41345 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -2557,10 +2557,25 @@ string IRGeneratorForStatements::binaryOperation( !TokenTraits::isShiftOp(_operator), "Have to use specific shift operation function for shifts." ); - if (IntegerType const* type = dynamic_cast(&_type)) + string fun; + if (TokenTraits::isBitOp(_operator)) { - string fun; - // TODO: Implement all operations for signed and unsigned types. + solAssert( + _type.category() == Type::Category::Integer || + _type.category() == Type::Category::FixedBytes, + ""); + switch (_operator) + { + case Token::BitOr: fun = "or"; break; + case Token::BitXor: fun = "xor"; break; + case Token::BitAnd: fun = "and"; break; + default: break; + } + } + else if (TokenTraits::isArithmeticOp(_operator)) + { + IntegerType const* type = dynamic_cast(&_type); + solAssert(type, ""); switch (_operator) { case Token::Add: @@ -2578,26 +2593,13 @@ string IRGeneratorForStatements::binaryOperation( case Token::Mod: fun = m_utils.checkedIntModFunction(*type); break; - case Token::BitOr: - fun = "or"; - break; - case Token::BitXor: - fun = "xor"; - break; - case Token::BitAnd: - fun = "and"; - break; default: break; } - - solUnimplementedAssert(!fun.empty(), ""); - return fun + "(" + _left + ", " + _right + ")\n"; } - else - solUnimplementedAssert(false, ""); - return {}; + solUnimplementedAssert(!fun.empty(), "Type: " + _type.toString()); + return fun + "(" + _left + ", " + _right + ")\n"; } std::string IRGeneratorForStatements::shiftOperation( diff --git a/test/libsolidity/semanticTests/interfaceID/homer.sol b/test/libsolidity/semanticTests/interfaceID/homer.sol index 243cba0b4..148e08f0f 100644 --- a/test/libsolidity/semanticTests/interfaceID/homer.sol +++ b/test/libsolidity/semanticTests/interfaceID/homer.sol @@ -29,6 +29,8 @@ contract Homer is ERC165, Simpson { } } +// ==== +// compileViaYul: also // ---- // supportsInterface(bytes4): left(0x01ffc9a0) -> false // supportsInterface(bytes4): left(0x01ffc9a7) -> true diff --git a/test/libsolidity/semanticTests/interfaceID/lisa.sol b/test/libsolidity/semanticTests/interfaceID/lisa.sol index 885cf9b24..7c50b5f16 100644 --- a/test/libsolidity/semanticTests/interfaceID/lisa.sol +++ b/test/libsolidity/semanticTests/interfaceID/lisa.sol @@ -40,6 +40,8 @@ contract Lisa is ERC165MappingImplementation, Simpson { } } +// ==== +// compileViaYul: also // ---- // supportsInterface(bytes4): left(0x01ffc9a0) -> false // supportsInterface(bytes4): left(0x01ffc9a7) -> true