aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerUtils.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-04-06 20:54:21 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-05-01 03:34:43 +0800
commit52c94418795f829c4a225fdf4742eec7a1961232 (patch)
treea62269e946982a1aaad47131390fedaf9478d99f /libsolidity/codegen/CompilerUtils.cpp
parentc3608eaf90b49771b2785d86bb0c73dca6e61046 (diff)
downloaddexon-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/CompilerUtils.cpp')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 46e81d49..45ad1f47 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -1274,8 +1274,9 @@ void CompilerUtils::leftShiftNumberOnStack(unsigned _bits)
void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned)
{
solAssert(_bits < 256, "");
- if (m_context.evmVersion().hasBitwiseShifting())
- m_context << _bits << (_isSigned ? Instruction::SAR : Instruction::SHR);
+ // NOTE: SAR rounds differently than SDIV
+ if (m_context.evmVersion().hasBitwiseShifting() && !_isSigned)
+ m_context << _bits << Instruction::SHR;
else
m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV);
}