Skip to content

Commit 0b9ab33

Browse files
authored
Merge pull request #12557 from nishant-sachdeva/adding_stack_height_checker_to_address_provider_in_case_type_function
Adding Stack Height Checker and modifying the number of POP instructions
2 parents e79a25e + 27d0480 commit 0b9ab33

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bugfixes:
1717
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
1818
* Natspec: Fix ICE when overriding a struct getter with a Natspec-documented return value and the name in the struct is different.
1919
* TypeChecker: Fix ICE when a constant variable declaration forward references a struct.
20+
* Code Generator: Fix ICE when accessing the members of external functions occupying more than two stack slots.
2021

2122

2223
Solc-Js:

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,9 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
17601760
case Type::Category::Function:
17611761
if (member == "selector")
17621762
{
1763+
auto const& functionType = dynamic_cast<FunctionType const&>(*_memberAccess.expression().annotation().type);
1764+
if (functionType.kind() == FunctionType::Kind::External)
1765+
CompilerUtils(m_context).popStackSlots(functionType.sizeOnStack() - 2);
17631766
m_context << Instruction::SWAP1 << Instruction::POP;
17641767
/// need to store it as bytes4
17651768
utils().leftShiftNumberOnStack(224);
@@ -1768,8 +1771,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
17681771
{
17691772
auto const& functionType = dynamic_cast<FunctionType const&>(*_memberAccess.expression().annotation().type);
17701773
solAssert(functionType.kind() == FunctionType::Kind::External, "");
1771-
// stack: <address> <function_id>
1772-
m_context << Instruction::POP;
1774+
CompilerUtils(m_context).popStackSlots(functionType.sizeOnStack() - 1);
17731775
}
17741776
else
17751777
solAssert(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
contract C {
2+
function g() external {}
3+
function h() external payable {}
4+
function test_function() external returns (bool){
5+
assert (
6+
this.g.address == this.g.address &&
7+
this.g{gas: 42}.address == this.g.address &&
8+
this.g{gas: 42}.selector == this.g.selector
9+
);
10+
assert (
11+
this.h.address == this.h.address &&
12+
this.h{gas: 42}.address == this.h.address &&
13+
this.h{gas: 42}.selector == this.h.selector
14+
);
15+
assert (
16+
this.h{gas: 42, value: 5}.address == this.h.address &&
17+
this.h{gas: 42, value: 5}.selector == this.h.selector
18+
);
19+
return true;
20+
}
21+
}
22+
// ====
23+
// compileViaYul: also
24+
// ----
25+
// test_function() -> true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract C {
2+
function f (address) external returns (bool) {
3+
this.f{gas: 42}.address;
4+
}
5+
}
6+
// ----
7+
// Warning 6321: (56-60): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
8+
// Warning 2018: (17-102): Function state mutability can be restricted to view

0 commit comments

Comments
 (0)