Skip to content

[Codegen] Do not perform cleanup on unsigned integers when loading from calldata. #5368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion libsolidity/codegen/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be a special case for uint256?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because we shift right by the appropriate amount. The use-case in mind actually uses uint32 (the 4 byte function selector).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is in the non-32byte branch.

Ah, forgot it is BE and not LE. The code looks good.

}
if (_fromCalldata)
convertType(_type, _type, true, false, true);
convertType(_type, _type, cleanupNeeded, false, true);

return numBytes;
}
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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--"))) +
Expand Down