mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Support .offset and .length for calldata bytes and string arrays.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f(uint[2][] calldata x) public returns (uint[2][] memory r) {
|
||||
assembly { x.offset := 0x44 x.length := 2 }
|
||||
r = x;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f(uint256[2][]): 0x0, 1, 8, 7, 6, 5 -> 0x20, 2, 8, 7, 6, 5
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
function f(uint[2][] calldata x) public returns (uint o, uint l, uint s) {
|
||||
assembly { l := x.length o := x.offset }
|
||||
uint[2] calldata t = x[1];
|
||||
// statically-sized arrays only use one slot, so we read directly.
|
||||
assembly { s := t }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256[2][]): 0x20, 2, 1, 2, 3, 4 -> 0x44, 2, 0x84
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) public returns (bytes memory) {
|
||||
assembly { x.offset := 1 x.length := 3 }
|
||||
return x;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(bytes): 0x20, 0, 0 -> 0x20, 3, 0x5754f80000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public pure returns (bytes calldata x) {
|
||||
assembly { x.offset := 0 x.length := 4 }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x20, 4, 0x26121ff000000000000000000000000000000000000000000000000000000000
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
function lenBytesRead(bytes calldata x) public returns (uint l) {
|
||||
assembly { l := x.length }
|
||||
}
|
||||
|
||||
function lenStringRead(string calldata x) public returns (uint l) {
|
||||
assembly { l := x.length }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// lenBytesRead(bytes): 0x20, 4, "abcd" -> 4
|
||||
// lenBytesRead(bytes): 0x20, 0, "abcd" -> 0x00
|
||||
// lenBytesRead(bytes): 0x20, 0x21, "abcd", "ef" -> 33
|
||||
// lenStringRead(string): 0x20, 4, "abcd" -> 4
|
||||
// lenStringRead(string): 0x20, 0, "abcd" -> 0x00
|
||||
// lenStringRead(string): 0x20, 0x21, "abcd", "ef" -> 33
|
||||
@@ -0,0 +1,19 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) public returns (uint r) {
|
||||
assembly { r := x.offset }
|
||||
}
|
||||
|
||||
function f(uint, bytes calldata x, uint) public returns (uint r, uint v) {
|
||||
assembly {
|
||||
r := x.offset
|
||||
v := x.length
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(bytes): 0x20, 0, 0 -> 0x44
|
||||
// f(bytes): 0x22, 0, 0, 0 -> 0x46
|
||||
// f(uint256,bytes,uint256): 7, 0x60, 8, 2, 0 -> 0x84, 2
|
||||
// f(uint256,bytes,uint256): 0, 0, 0 -> 0x24, 0x00
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
function f(uint, bytes calldata x, uint) public returns (uint r, uint v) {
|
||||
assembly {
|
||||
x.offset := 8
|
||||
x.length := 20
|
||||
}
|
||||
assembly {
|
||||
r := x.offset
|
||||
v := x.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,bytes,uint256): 7, 0x60, 8, 2, 0 -> 8, 0x14
|
||||
// f(uint256,bytes,uint256): 0, 0, 0 -> 8, 0x14
|
||||
@@ -25,6 +25,8 @@ contract C {
|
||||
return data().a;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// get() -> 0
|
||||
// mappingAccess(uint256): 1 -> 0, 0
|
||||
|
||||
Reference in New Issue
Block a user