Skip to content

Commit

Permalink
Warn if returndatasize/returndatacopy is used
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 24, 2017
1 parent c1f1eb1 commit 31e727c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libsolidity/inlineasm/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bool AsmAnalyzer::operator()(assembly::Instruction const& _instruction)
auto const& info = instructionInfo(_instruction.instruction);
m_stackHeight += info.ret - info.args;
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
warnOnFutureInstruction(_instruction.instruction, _instruction.location);
return true;
}

Expand Down Expand Up @@ -157,6 +158,7 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
if (!(*this)(_instr.instruction))
success = false;
m_info.stackHeightInfo[&_instr] = m_stackHeight;
warnOnFutureInstruction(_instr.instruction.instruction, _instr.location);
return success;
}

Expand Down Expand Up @@ -411,3 +413,21 @@ Scope& AsmAnalyzer::scope(Block const* _block)
solAssert(scopePtr, "Scope requested but not present.");
return *scopePtr;
}

void AsmAnalyzer::warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location)
{
switch (_instr)
{
case solidity::Instruction::RETURNDATASIZE:
case solidity::Instruction::RETURNDATACOPY:
m_errors.push_back(make_shared<Error>(
Error::Type::Warning,
"The RETURNDATASIZE/RETURNDATACOPY instructions are only available after "
"the Metropolis hard fork. Before that they act as an invalid instruction.",
_location
));
break;
default:
break;
}
}
1 change: 1 addition & 0 deletions libsolidity/inlineasm/AsmAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class AsmAnalyzer: public boost::static_visitor<bool>
bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1));
bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location);
Scope& scope(assembly::Block const* _block);
void warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location);

/// This is used when we enter the body of a function definition. There, the parameters
/// and return parameters appear as variables which are already on the stack before
Expand Down

0 comments on commit 31e727c

Please sign in to comment.