Merge pull request #2470 from chriseth/sol_fix_bytesComparison

Fix comparison between bytes types.
This commit is contained in:
Gav Wood 2015-07-14 18:16:54 +02:00
commit a85c5bd0b0

View File

@ -935,24 +935,27 @@ void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type
} }
else else
{ {
IntegerType const& type = dynamic_cast<IntegerType const&>(_type); bool isSigned = false;
bool const c_isSigned = type.isSigned(); if (auto type = dynamic_cast<IntegerType const*>(&_type))
isSigned = type->isSigned();
switch (_operator) switch (_operator)
{ {
case Token::GreaterThanOrEqual: case Token::GreaterThanOrEqual:
m_context << (c_isSigned ? eth::Instruction::SLT : eth::Instruction::LT) m_context <<
<< eth::Instruction::ISZERO; (isSigned ? eth::Instruction::SLT : eth::Instruction::LT) <<
eth::Instruction::ISZERO;
break; break;
case Token::LessThanOrEqual: case Token::LessThanOrEqual:
m_context << (c_isSigned ? eth::Instruction::SGT : eth::Instruction::GT) m_context <<
<< eth::Instruction::ISZERO; (isSigned ? eth::Instruction::SGT : eth::Instruction::GT) <<
eth::Instruction::ISZERO;
break; break;
case Token::GreaterThan: case Token::GreaterThan:
m_context << (c_isSigned ? eth::Instruction::SGT : eth::Instruction::GT); m_context << (isSigned ? eth::Instruction::SGT : eth::Instruction::GT);
break; break;
case Token::LessThan: case Token::LessThan:
m_context << (c_isSigned ? eth::Instruction::SLT : eth::Instruction::LT); m_context << (isSigned ? eth::Instruction::SLT : eth::Instruction::LT);
break; break;
default: default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown comparison operator.")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown comparison operator."));