mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix inline assembly assignments to calldata structs and statically-sized arrays.
This commit is contained in:
parent
623b4ba366
commit
fc37b18e88
@ -16,6 +16,7 @@ Compiler Features:
|
|||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Code Generator: Fix ICE on assigning to calldata structs and statically-sized calldata arrays in inline assembly.
|
||||||
* Code Generator: Use stable source order for ABI functions.
|
* Code Generator: Use stable source order for ABI functions.
|
||||||
* Opcode Optimizer: Prevent the optimizer from running multiple times to avoid potential bytecode differences for referenced code.
|
* Opcode Optimizer: Prevent the optimizer from running multiple times to avoid potential bytecode differences for referenced code.
|
||||||
* Name Resolver: Fix that when importing an aliased symbol using ``import {AliasedName} from "a.sol"`` it would use the original name of the symbol and not the aliased one.
|
* Name Resolver: Fix that when importing an aliased symbol using ``import {AliasedName} from "a.sol"`` it would use the original name of the symbol and not the aliased one.
|
||||||
|
@ -860,16 +860,29 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
}
|
}
|
||||||
else if (variable->type()->dataStoredIn(DataLocation::CallData))
|
else if (variable->type()->dataStoredIn(DataLocation::CallData))
|
||||||
{
|
{
|
||||||
auto const* arrayType = dynamic_cast<ArrayType const*>(variable->type());
|
if (auto const* arrayType = dynamic_cast<ArrayType const*>(variable->type()))
|
||||||
solAssert(
|
{
|
||||||
arrayType && arrayType->isDynamicallySized() && arrayType->dataStoredIn(DataLocation::CallData),
|
if (arrayType->isDynamicallySized())
|
||||||
""
|
{
|
||||||
);
|
|
||||||
solAssert(suffix == "offset" || suffix == "length", "");
|
solAssert(suffix == "offset" || suffix == "length", "");
|
||||||
solAssert(variable->type()->sizeOnStack() == 2, "");
|
solAssert(variable->type()->sizeOnStack() == 2, "");
|
||||||
if (suffix == "length")
|
if (suffix == "length")
|
||||||
stackDiff--;
|
stackDiff--;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
solAssert(variable->type()->sizeOnStack() == 1, "");
|
||||||
|
solAssert(suffix.empty(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto const* structType = dynamic_cast<StructType const*>(variable->type());
|
||||||
|
solAssert(structType, "");
|
||||||
|
solAssert(variable->type()->sizeOnStack() == 1, "");
|
||||||
|
solAssert(suffix.empty(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
solAssert(suffix.empty(), "");
|
solAssert(suffix.empty(), "");
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint[2][2] calldata x) public returns (uint[2][2] memory r) {
|
||||||
|
assembly { x := 0x24 }
|
||||||
|
r = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(uint256[2][2]): 0x0, 8, 7, 6, 5 -> 8, 7, 6, 5
|
@ -0,0 +1,18 @@
|
|||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
struct S { uint256 x; }
|
||||||
|
struct S2 { uint256 x; uint256 y; }
|
||||||
|
function f(S calldata s, S2 calldata s2) public pure returns (uint256 r, uint256 r2) {
|
||||||
|
assembly {
|
||||||
|
s := s2
|
||||||
|
s2 := 4
|
||||||
|
}
|
||||||
|
r = s.x;
|
||||||
|
r2 = s2.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f((uint256),(uint256,uint256)): 0x42, 0x07, 0x77 -> 0x07, 0x42
|
@ -0,0 +1,23 @@
|
|||||||
|
pragma abicoder v2;
|
||||||
|
contract C {
|
||||||
|
struct S { int8 x; int8 y; }
|
||||||
|
function f() internal pure returns(S calldata s) {
|
||||||
|
assembly {
|
||||||
|
s := 0x24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function g() public pure returns(int8, int8) {
|
||||||
|
S calldata s = f();
|
||||||
|
return (s.x, s.y);
|
||||||
|
}
|
||||||
|
function h() public pure returns(uint256) { f(); return 0x42; }
|
||||||
|
function i() public pure returns(uint256) { abi.decode(msg.data[4:], (S)); return 0x42; }
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// g(): 0xCAFFEE, 0x42, 0x21 -> 0x42, 0x21
|
||||||
|
// g(): 0xCAFFEE, 0x4242, 0x2121 -> FAILURE
|
||||||
|
// g(): 0xCAFFEE, 0x42 -> 0x42, 0
|
||||||
|
// h() -> 0x42
|
||||||
|
// i() -> FAILURE
|
Loading…
Reference in New Issue
Block a user