mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not use SAR instead of SDIV in shifts because it rounds differently
This commit is contained in:
1 parent
c3608eaf90
commit
52c9441879
3 files changed
+10
-7
No files matched your search
@@ -1718,8 +1718,9 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co
|
||||
m_context << u256(2) << Instruction::EXP << Instruction::MUL;
|
||||
break;
|
||||
case Token::SAR:
|
||||
if (m_context.evmVersion().hasBitwiseShifting())
|
||||
m_context << (c_valueSigned ? Instruction::SAR : Instruction::SHR);
|
||||
// NOTE: SAR rounds differently than SDIV
|
||||
if (m_context.evmVersion().hasBitwiseShifting() && !c_valueSigned)
|
||||
m_context << Instruction::SHR;
|
||||
else
|
||||
m_context << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user