-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
.address
and .selector
in inside assembly for external fu…
…nction pointers
- Loading branch information
Showing
17 changed files
with
210 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/libsolidity/semanticTests/inlineAssembly/external_function_pointer_address.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
contract C { | ||
function testFunction() external {} | ||
|
||
function testYul() public returns (address adr) { | ||
function() external fp = this.testFunction; | ||
|
||
assembly { | ||
adr := fp.address | ||
} | ||
} | ||
function testSol() public returns (address) { | ||
return this.testFunction.address; | ||
} | ||
} | ||
// ==== | ||
// compileViaYul: also | ||
// ---- | ||
// testYul() -> 0x0fdd67305928fcac8d213d1e47bfa6165cd0b87b | ||
// testSol() -> 0x0fdd67305928fcac8d213d1e47bfa6165cd0b87b |
18 changes: 18 additions & 0 deletions
18
...libsolidity/semanticTests/inlineAssembly/external_function_pointer_address_assignment.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
contract C { | ||
function testFunction() external {} | ||
|
||
function testYul(address newAddress) view public returns (address adr) { | ||
function() external fp = this.testFunction; | ||
|
||
assembly { | ||
fp.address := newAddress | ||
} | ||
|
||
return fp.address; | ||
} | ||
} | ||
// ==== | ||
// compileViaYul: also | ||
// ---- | ||
// testYul(address): 0x1234567890 -> 0x1234567890 | ||
// testYul(address): 0xC0FFEE3EA7 -> 0xC0FFEE3EA7 |
23 changes: 23 additions & 0 deletions
23
test/libsolidity/semanticTests/inlineAssembly/external_function_pointer_selector.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
contract C { | ||
function testFunction() external {} | ||
|
||
function testYul() public returns (uint32) { | ||
function() external fp = this.testFunction; | ||
uint selectorValue = 0; | ||
|
||
assembly { | ||
selectorValue := fp.selector | ||
} | ||
|
||
// Value is right-aligned, we shift it so it can be compared | ||
return uint32(bytes4(bytes32(selectorValue << (256 - 32)))); | ||
} | ||
function testSol() public returns (uint32) { | ||
return uint32(this.testFunction.selector); | ||
} | ||
} | ||
// ==== | ||
// compileViaYul: also | ||
// ---- | ||
// testYul() -> 0xe16b4a9b | ||
// testSol() -> 0xe16b4a9b |
18 changes: 18 additions & 0 deletions
18
...ibsolidity/semanticTests/inlineAssembly/external_function_pointer_selector_assignment.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
contract C { | ||
function testFunction() external {} | ||
|
||
function testYul(uint32 newSelector) view public returns (uint32) { | ||
function() external fp = this.testFunction; | ||
|
||
assembly { | ||
fp.selector := newSelector | ||
} | ||
|
||
return uint32(fp.selector); | ||
} | ||
} | ||
// ==== | ||
// compileViaYul: also | ||
// ---- | ||
// testYul(uint32): 0x12345678 -> 0x12345678 | ||
// testYul(uint32): 0xABCDEF00 -> 0xABCDEF00 |
15 changes: 15 additions & 0 deletions
15
test/libsolidity/syntaxTests/inlineAssembly/invalid/external_function_pointer_offset.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract C { | ||
function testFunction() external {} | ||
|
||
function testYul() public { | ||
function() external fp = this.testFunction; | ||
|
||
uint myOffset; | ||
|
||
assembly { | ||
myOffset := fp.offset | ||
} | ||
} | ||
} | ||
// ---- | ||
// TypeError 9272: (173-182): Variables of type function pointer only support ".selector" and ".address". |
18 changes: 18 additions & 0 deletions
18
test/libsolidity/syntaxTests/inlineAssembly/invalid/internal_function_pointer_address.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
contract C { | ||
function testFunction() internal {} | ||
|
||
function testYul() public returns (address adr) { | ||
function() internal fp = testFunction; | ||
uint selectorValue = 0; | ||
|
||
assembly { | ||
adr := fp.address | ||
} | ||
} | ||
function testSol() public returns (address) { | ||
return testFunction.address; | ||
} | ||
} | ||
// ---- | ||
// TypeError 8533: (193-203): Only Variables of type external function pointer support ".selector" and ".address". | ||
// TypeError 9582: (267-287): Member "address" not found or not visible after argument-dependent lookup in function (). |
20 changes: 20 additions & 0 deletions
20
test/libsolidity/syntaxTests/inlineAssembly/invalid/internal_function_pointer_selector.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
contract C { | ||
function testFunction() internal {} | ||
|
||
function testYul() public returns (uint32) { | ||
function() internal fp = testFunction; | ||
uint selectorValue = 0; | ||
|
||
assembly { | ||
selectorValue := fp.selector | ||
} | ||
|
||
return uint32(bytes4(bytes32(selectorValue))); | ||
} | ||
function testSol() public returns (uint32) { | ||
return uint32(testFunction.selector); | ||
} | ||
} | ||
// ---- | ||
// TypeError 8533: (198-209): Only Variables of type external function pointer support ".selector" and ".address". | ||
// TypeError 9582: (329-350): Member "selector" not found or not visible after argument-dependent lookup in function (). |