diff options
author | chriseth <chris@ethereum.org> | 2018-11-08 06:52:13 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-11-15 04:52:30 +0800 |
commit | 727e3f24bc57b9470b7972fe882d60117625afe5 (patch) | |
tree | 199d350f723cd845a9fffd7f09811f187e7afe9d | |
parent | 1e4765fba7a061d8440b5bdb57ba074874c7e171 (diff) | |
download | dexon-solidity-727e3f24bc57b9470b7972fe882d60117625afe5.tar.gz dexon-solidity-727e3f24bc57b9470b7972fe882d60117625afe5.tar.zst dexon-solidity-727e3f24bc57b9470b7972fe882d60117625afe5.zip |
Do not perform cleanup on unsigned integers when loading from calldata.
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 9 | ||||
-rw-r--r-- | test/libsolidity/Assembly.cpp | 2 |
3 files changed, 10 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md index b5e7eed8..b2b03ae4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ Language Features: Compiler Features: * Build System: LLL is not built anymore by default. Must configure it with CMake as `-DLLL=ON`. + * Code generator: Do not perform redundant double cleanup on unsigned integers when loading from calldata. Bugfixes: diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 90eb74fe..a0d11017 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1236,6 +1236,7 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda } solAssert(numBytes <= 32, "Static memory load of more than 32 bytes requested."); m_context << (_fromCalldata ? Instruction::CALLDATALOAD : Instruction::MLOAD); + bool cleanupNeeded = true; if (isExternalFunctionType) splitExternalFunctionType(true); else if (numBytes != 32) @@ -1245,10 +1246,16 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda int shiftFactor = (32 - numBytes) * 8; rightShiftNumberOnStack(shiftFactor); if (leftAligned) + { leftShiftNumberOnStack(shiftFactor); + cleanupNeeded = false; + } + else if (IntegerType const* intType = dynamic_cast<IntegerType const*>(&_type)) + if (!intType->isSigned()) + cleanupNeeded = false; } if (_fromCalldata) - convertType(_type, _type, true, false, true); + convertType(_type, _type, cleanupNeeded, false, true); return numBytes; } diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index e815d7d5..5e157678 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(location_test) AssemblyItems items = compileContract(sourceCode); bool hasShifts = dev::test::Options::get().evmVersion().hasBitwiseShifting(); vector<SourceLocation> locations = - vector<SourceLocation>(hasShifts ? 23 : 24, SourceLocation(2, 82, make_shared<string>(""))) + + vector<SourceLocation>(hasShifts ? 21 : 22, SourceLocation(2, 82, make_shared<string>(""))) + vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))) + vector<SourceLocation>(1, SourceLocation(8, 17, make_shared<string>("--CODEGEN--"))) + vector<SourceLocation>(3, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) + |