mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix argument stack slot reuse for functions without return variables.
This commit is contained in:
parent
f1a474e599
commit
8a4497a8d3
@ -402,7 +402,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
|
||||
subTransform.deleteVariable(var);
|
||||
}
|
||||
|
||||
if (!m_allowStackOpt || _function.returnVariables.empty())
|
||||
if (!m_allowStackOpt)
|
||||
subTransform.setupReturnVariablesAndFunctionExit();
|
||||
|
||||
subTransform(_function.body);
|
||||
@ -592,6 +592,7 @@ void CodeTransform::visitExpression(Expression const& _expression)
|
||||
|
||||
void CodeTransform::setupReturnVariablesAndFunctionExit()
|
||||
{
|
||||
yulAssert(isInsideFunction(), "");
|
||||
yulAssert(!returnVariablesAndFunctionExitAreSetup(), "");
|
||||
yulAssert(m_scope, "");
|
||||
|
||||
@ -654,7 +655,8 @@ void CodeTransform::visitStatements(vector<Statement> const& _statements)
|
||||
{
|
||||
freeUnusedVariables();
|
||||
if (
|
||||
!m_delayedReturnVariables.empty() &&
|
||||
isInsideFunction() &&
|
||||
!returnVariablesAndFunctionExitAreSetup() &&
|
||||
statementNeedsReturnVariableSetup(statement, m_delayedReturnVariables)
|
||||
)
|
||||
setupReturnVariablesAndFunctionExit();
|
||||
|
||||
@ -183,6 +183,10 @@ private:
|
||||
{
|
||||
return m_functionExitStackHeight.has_value();
|
||||
}
|
||||
bool isInsideFunction() const
|
||||
{
|
||||
return m_functionExitLabel.has_value();
|
||||
}
|
||||
|
||||
AbstractAssembly& m_assembly;
|
||||
AsmAnalysisInfo& m_info;
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
{
|
||||
function f(x, y) {
|
||||
mstore(0x80, x)
|
||||
if calldataload(0) { sstore(y, y) }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// stackOptimization: true
|
||||
// ----
|
||||
// PUSH1 0x17
|
||||
// JUMP
|
||||
// JUMPDEST
|
||||
// DUP1
|
||||
// PUSH1 0x80
|
||||
// MSTORE
|
||||
// POP
|
||||
// PUSH1 0x0
|
||||
// CALLDATALOAD
|
||||
// ISZERO
|
||||
// PUSH1 0x13
|
||||
// JUMPI
|
||||
// DUP1
|
||||
// DUP2
|
||||
// SSTORE
|
||||
// JUMPDEST
|
||||
// POP
|
||||
// JUMPDEST
|
||||
// JUMP
|
||||
// JUMPDEST
|
||||
Loading…
Reference in New Issue
Block a user