diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-06 20:54:21 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-05-01 03:34:43 +0800 |
commit | 52c94418795f829c4a225fdf4742eec7a1961232 (patch) | |
tree | a62269e946982a1aaad47131390fedaf9478d99f /libsolidity/codegen/ExpressionCompiler.cpp | |
parent | c3608eaf90b49771b2785d86bb0c73dca6e61046 (diff) | |
download | dexon-solidity-52c94418795f829c4a225fdf4742eec7a1961232.tar.gz dexon-solidity-52c94418795f829c4a225fdf4742eec7a1961232.tar.zst dexon-solidity-52c94418795f829c4a225fdf4742eec7a1961232.zip |
Do not use SAR instead of SDIV in shifts because it rounds differently
Diffstat (limited to 'libsolidity/codegen/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 1a33fe7c..019867c5 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -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; |