Merge pull request #12048 from ethereum/tests-assembly-user-defined-value-type

Tests for assembly access of user defined value types.
This commit is contained in:
chriseth 2021-09-28 17:57:36 +02:00 committed by GitHub
commit 89d959d7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,35 @@
pragma abicoder v1;
type MyBytes2 is bytes2;
contract C {
function f(MyBytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function g(bytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function h(uint256 val) external returns (MyBytes2) {
MyBytes2 ret;
assembly {
ret := val
}
return ret;
}
}
// ====
// compileViaYul: false
// ----
// f(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// f(bytes2): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,35 @@
pragma abicoder v2;
type MyBytes2 is bytes2;
contract C {
function f(MyBytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function g(bytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function h(uint256 val) external returns (MyBytes2) {
MyBytes2 ret;
assembly {
ret := val
}
return ret;
}
}
// ====
// compileViaYul: also
// ----
// f(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// f(bytes2): "abcdef" -> FAILURE
// g(bytes2): "abcdef" -> FAILURE
// h(uint256): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000