From 05af6c92556acac917983b1a8e0e9e62d28de573 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 24 May 2017 21:51:54 +0100 Subject: Warn if returndatasize/returndatacopy is used --- libsolidity/inlineasm/AsmAnalysis.cpp | 20 +++++++++++++++++++- libsolidity/inlineasm/AsmAnalysis.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 13852880..36ac0e75 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -65,6 +65,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; } @@ -149,6 +150,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; } @@ -431,7 +433,6 @@ Scope& AsmAnalyzer::scope(Block const* _block) solAssert(scopePtr, "Scope requested but not present."); return *scopePtr; } - void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location) { if (!m_julia) @@ -443,3 +444,20 @@ void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _loc "\"" + type + "\" is not a valid type (user defined types are not yet supported)." ); } + +void AsmAnalyzer::warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location) +{ + switch (_instr) + { + case solidity::Instruction::RETURNDATASIZE: + case solidity::Instruction::RETURNDATACOPY: + m_errorReporter.warning( + _location, + "The RETURNDATASIZE/RETURNDATACOPY instructions are only available after " + "the Metropolis hard fork. Before that they act as an invalid instruction." + ); + break; + default: + break; + } +} diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h index e7748bcf..55b409ba 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libsolidity/inlineasm/AsmAnalysis.h @@ -97,6 +97,7 @@ private: Scope& scope(assembly::Block const* _block); void expectValidType(std::string const& type, SourceLocation const& _location); + void warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location); int m_stackHeight = 0; julia::ExternalIdentifierAccess::Resolver m_resolver; -- cgit