Skip to content

Commit

Permalink
Fixed a ICE on calldata to struct member copy
Browse files Browse the repository at this point in the history
  • Loading branch information
hrkrshnn committed Jan 24, 2022
1 parent 3f401eb commit aa99de4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2982,8 +2982,11 @@ void IRGeneratorForStatements::writeToLValue(IRLValue const& _lvalue, IRVariable
{
solAssert(_lvalue.type.sizeOnStack() == 1);
auto const* valueReferenceType = dynamic_cast<ReferenceType const*>(&_value.type());
solAssert(valueReferenceType && valueReferenceType->dataStoredIn(DataLocation::Memory));
appendCode() << "mstore(" + _memory.address + ", " + _value.part("mpos").name() + ")\n";
solAssert(valueReferenceType);
if (valueReferenceType->dataStoredIn(DataLocation::Memory))
appendCode() << "mstore(" + _memory.address + ", " + _value.part("mpos").name() + ")\n";
else
appendCode() << "mstore(" + _memory.address + ", " + m_utils.conversionFunction(_value.type(), _lvalue.type) + "(" + _value.commaSeparatedList() + "))\n";
}
},
[&](IRLValue::Stack const& _stack) { assign(_stack.variable, _value); },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
struct St0 {
bytes el0;
}
contract C {
function f() external returns (St0 memory) {
St0 memory x;
x.el0 = msg.data;
return x;
}

function g() external returns (St0 memory) {
bytes memory temp = msg.data;
St0 memory x;
x.el0 = temp;
return x;
}

function hashes() external returns (bytes4, bytes4) {
return (this.f.selector, this.g.selector);
}

function large(uint256, uint256, uint256, uint256) external returns (St0 memory) {
St0 memory x;
x.el0 = msg.data;
return x;
}

function another_large(uint256, uint256, uint256, uint256) external returns (St0 memory) {
bytes memory temp = msg.data;
St0 memory x;
x.el0 = temp;
return x;
}

}
// ====
// compileToEwasm: also
// compileViaYul: also
// ----
// f() -> 0x20, 0x20, 4, 0x26121ff000000000000000000000000000000000000000000000000000000000
// g() -> 0x20, 0x20, 4, 0xe2179b8e00000000000000000000000000000000000000000000000000000000
// hashes() -> 0x26121ff000000000000000000000000000000000000000000000000000000000, 0xe2179b8e00000000000000000000000000000000000000000000000000000000
// large(uint256,uint256,uint256,uint256): 1, 2, 3, 4 -> 0x20, 0x20, 0x84, 0xe02492f800000000000000000000000000000000000000000000000000000000, 0x100000000000000000000000000000000000000000000000000000000, 0x200000000000000000000000000000000000000000000000000000000, 0x300000000000000000000000000000000000000000000000000000000, 0x400000000000000000000000000000000000000000000000000000000
// another_large(uint256,uint256,uint256,uint256): 1, 2, 3, 4 -> 0x20, 0x20, 0x84, 0x2a46f85a00000000000000000000000000000000000000000000000000000000, 0x100000000000000000000000000000000000000000000000000000000, 0x200000000000000000000000000000000000000000000000000000000, 0x300000000000000000000000000000000000000000000000000000000, 0x400000000000000000000000000000000000000000000000000000000

0 comments on commit aa99de4

Please sign in to comment.