Merge pull request #7026 from ethereum/asmConstants

Support direct constants in inline assembly.
This commit is contained in:
chriseth
2019-07-02 14:21:24 +02:00
committed by GitHub
11 changed files with 122 additions and 10 deletions
@@ -0,0 +1,18 @@
contract C {
uint constant a = 2;
bytes2 constant b = 0xabcd;
bytes3 constant c = "abc";
bool constant d = true;
address payable constant e = 0x1212121212121212121212121212121212121212;
function f() public pure returns (uint w, bytes2 x, bytes3 y, bool z, address t) {
assembly {
w := a
x := b
y := c
z := d
t := e
}
}
}
// ----
// f() -> 2, left(0xabcd), left(0x616263), true, 0x1212121212121212121212121212121212121212
@@ -0,0 +1,13 @@
contract C {
uint constant x = 2**20;
bool constant b = true;
bytes4 constant s = "ab";
function f() public pure {
assembly {
let c1 := x
let c2 := b
let c3 := s
}
}
}
// ----
@@ -0,0 +1,10 @@
contract C {
string constant x = "abc";
function f() public pure {
assembly {
let a := x
}
}
}
// ----
// TypeError: (115-116): Only direct number constants are supported by inline assembly.
@@ -0,0 +1,9 @@
contract C {
uint constant x = 2**20;
function f() public pure {
assembly {
let a := x
}
}
}
// ----
@@ -0,0 +1,11 @@
contract C {
uint constant a = 2;
uint constant b = a;
function f() public pure {
assembly {
let x := b
}
}
}
// ----
// TypeError: (134-135): Only direct number constants are supported by inline assembly.
@@ -1,10 +1,9 @@
contract test {
uint constant x = 1;
function f() public {
function f() public pure {
assembly {
let y := x
}
}
}
// ----
// TypeError: (107-108): Constant variables not supported by inline assembly.
@@ -7,4 +7,4 @@ contract test {
}
}
// ----
// TypeError: (98-99): Constant variables not supported by inline assembly.
// TypeError: (98-99): Constant variables cannot be assigned to.
@@ -7,4 +7,4 @@ contract test {
}
}
// ----
// TypeError: (112-120): Constant variables not supported by inline assembly.
// TypeError: (112-120): The suffixes _offset and _slot can only be used on non-constant storage variables.