mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
New tests.
This commit is contained in:
parent
77932edb02
commit
090a46c2a5
@ -0,0 +1,26 @@
|
||||
type MyInt8 is int8;
|
||||
contract C {
|
||||
MyInt8 public x = MyInt8.wrap(-5);
|
||||
|
||||
/// The most significant bit is flipped to 0
|
||||
function create_dirty_slot() external {
|
||||
uint mask = 2**255 -1;
|
||||
assembly {
|
||||
let value := sload(x.slot)
|
||||
sstore(x.slot, and(mask, value))
|
||||
}
|
||||
}
|
||||
|
||||
function read_unclean_value() external returns (bytes32 ret) {
|
||||
MyInt8 value = x;
|
||||
assembly {
|
||||
ret := value
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// x() -> -5
|
||||
// create_dirty_slot() ->
|
||||
// read_unclean_value() -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
|
@ -0,0 +1,21 @@
|
||||
type MyInt is int16;
|
||||
type MyBytes is bytes2;
|
||||
contract C {
|
||||
MyInt immutable a = MyInt.wrap(-2);
|
||||
MyBytes immutable b = MyBytes.wrap("ab");
|
||||
function() internal returns (uint) immutable f = g;
|
||||
function direct() view external returns (MyInt, MyBytes) {
|
||||
return (a, b);
|
||||
}
|
||||
function viaasm() view external returns (bytes32 x, bytes32 y) {
|
||||
MyInt _a = a;
|
||||
MyBytes _b = b;
|
||||
assembly { x := _a y := _b }
|
||||
}
|
||||
function g() internal pure returns (uint) { return 2; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// direct() -> -2, 0x6162000000000000000000000000000000000000000000000000000000000000
|
||||
// viaasm() -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 0x6162000000000000000000000000000000000000000000000000000000000000
|
@ -0,0 +1,35 @@
|
||||
type MyInt is int16;
|
||||
contract C {
|
||||
bytes2 first = "ab";
|
||||
MyInt public a = MyInt.wrap(-2);
|
||||
bytes2 third = "ef";
|
||||
function direct() external returns (MyInt) {
|
||||
return a;
|
||||
}
|
||||
function indirect() external returns (int16) {
|
||||
return MyInt.unwrap(a);
|
||||
}
|
||||
function toMemDirect() external returns (MyInt[1] memory) {
|
||||
return [a];
|
||||
}
|
||||
function toMemIndirect() external returns (int16[1] memory) {
|
||||
return [MyInt.unwrap(a)];
|
||||
}
|
||||
function div() external returns (int16) {
|
||||
return MyInt.unwrap(a) / 2;
|
||||
}
|
||||
function viaasm() external returns (bytes32 x) {
|
||||
MyInt st = a;
|
||||
assembly { x := st }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a() -> -2
|
||||
// direct() -> -2
|
||||
// indirect() -> -2
|
||||
// toMemDirect() -> -2
|
||||
// toMemIndirect() -> -2
|
||||
// div() -> -1
|
||||
// viaasm() -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
|
Loading…
Reference in New Issue
Block a user