mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use pointer to string for efficiency
This commit is contained in:
parent
41bdc9b673
commit
ea9e849ee4
@ -93,16 +93,18 @@ string ProtoConverter::visit(Literal const& _x)
|
||||
void ProtoConverter::consolidateVarDeclsInFunctionDef()
|
||||
{
|
||||
m_currentFuncVars.clear();
|
||||
auto &scopes = m_funcVars.back();
|
||||
for (auto &s: scopes)
|
||||
m_currentFuncVars.insert(m_currentFuncVars.end(), s.begin(), s.end());
|
||||
auto const& scopes = m_funcVars.back();
|
||||
for (auto const& s: scopes)
|
||||
for (auto const& var: s)
|
||||
m_currentFuncVars.push_back(&var);
|
||||
}
|
||||
|
||||
void ProtoConverter::consolidateGlobalVarDecls()
|
||||
{
|
||||
m_globalVars.clear();
|
||||
for (auto &scope: m_variables)
|
||||
m_globalVars.insert(m_globalVars.end(), scope.begin(), scope.end());
|
||||
m_currentGlobalVars.clear();
|
||||
for (auto const& scope: m_globalVars)
|
||||
for (auto const& var: scope)
|
||||
m_currentGlobalVars.push_back(&var);
|
||||
}
|
||||
|
||||
bool ProtoConverter::varDeclAvailable()
|
||||
@ -115,7 +117,7 @@ bool ProtoConverter::varDeclAvailable()
|
||||
else
|
||||
{
|
||||
consolidateGlobalVarDecls();
|
||||
return m_globalVars.size() > 0;
|
||||
return m_currentGlobalVars.size() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,13 +133,13 @@ void ProtoConverter::visit(VarRef const& _x)
|
||||
{
|
||||
// Ensure that there is at least one variable declaration to reference in function scope.
|
||||
yulAssert(m_currentFuncVars.size() > 0, "Proto fuzzer: No variables to reference.");
|
||||
m_output << m_currentFuncVars[_x.varnum() % m_currentFuncVars.size()];
|
||||
m_output << *m_currentFuncVars[_x.varnum() % m_currentFuncVars.size()];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure that there is at least one variable declaration to reference in nested scopes.
|
||||
yulAssert(m_globalVars.size() > 0, "Proto fuzzer: No global variables to reference.");
|
||||
m_output << m_globalVars[_x.varnum() % m_globalVars.size()];
|
||||
yulAssert(m_currentGlobalVars.size() > 0, "Proto fuzzer: No global variables to reference.");
|
||||
m_output << *m_currentGlobalVars[_x.varnum() % m_currentGlobalVars.size()];
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,7 +284,7 @@ void ProtoConverter::visit(VarDecl const& _x)
|
||||
if (m_inFunctionDef)
|
||||
m_funcVars.back().back().push_back(varName);
|
||||
else
|
||||
m_variables.back().push_back(varName);
|
||||
m_globalVars.back().push_back(varName);
|
||||
}
|
||||
|
||||
void ProtoConverter::visit(TypedVarDecl const& _x)
|
||||
@ -350,7 +352,7 @@ void ProtoConverter::visit(TypedVarDecl const& _x)
|
||||
if (m_inFunctionDef)
|
||||
m_funcVars.back().back().push_back(varName);
|
||||
else
|
||||
m_variables.back().push_back(varName);
|
||||
m_globalVars.back().push_back(varName);
|
||||
}
|
||||
|
||||
void ProtoConverter::visit(UnaryOp const& _x)
|
||||
@ -1134,7 +1136,7 @@ void ProtoConverter::openBlockScope()
|
||||
if (m_inFunctionDef)
|
||||
m_funcVars.back().push_back(vector<string>{});
|
||||
else
|
||||
m_variables.push_back(vector<string>{});
|
||||
m_globalVars.push_back(vector<string>{});
|
||||
}
|
||||
|
||||
void ProtoConverter::openFunctionScope(vector<string> const& _funcParams)
|
||||
@ -1173,8 +1175,8 @@ void ProtoConverter::closeBlockScope()
|
||||
m_scopeFuncs.pop_back();
|
||||
if (!m_inFunctionDef)
|
||||
{
|
||||
if (!m_variables.empty())
|
||||
m_variables.pop_back();
|
||||
if (!m_globalVars.empty())
|
||||
m_globalVars.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1197,7 +1199,7 @@ void ProtoConverter::addVarsToScope(vector<string> const& _vars)
|
||||
if (m_inFunctionDef)
|
||||
m_funcVars.back().back().insert(m_funcVars.back().back().end(), _vars.begin(), _vars.end());
|
||||
else
|
||||
m_variables.back().insert(m_variables.back().end(), _vars.begin(), _vars.end());
|
||||
m_globalVars.back().insert(m_globalVars.back().end(), _vars.begin(), _vars.end());
|
||||
}
|
||||
|
||||
void ProtoConverter::visit(Block const& _x)
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
ProtoConverter()
|
||||
{
|
||||
m_funcVars = std::vector<std::vector<std::vector<std::string>>>{};
|
||||
m_variables = std::vector<std::vector<std::string>>{};
|
||||
m_globalVars = std::vector<std::vector<std::string>>{};
|
||||
m_inForBodyScope = false;
|
||||
m_inForInitScope = false;
|
||||
m_numNestedForLoops = 0;
|
||||
@ -312,13 +312,13 @@ private:
|
||||
/// Variables in all function definitions
|
||||
std::vector<std::vector<std::vector<std::string>>> m_funcVars;
|
||||
/// Variables in current function definition
|
||||
std::vector<std::string> m_currentFuncVars;
|
||||
std::vector<std::string const*> m_currentFuncVars;
|
||||
/// Variables in global scope
|
||||
std::vector<std::string> m_globalVars;
|
||||
std::vector<std::string const*> m_currentGlobalVars;
|
||||
/// Functions in current scope
|
||||
std::vector<std::vector<std::string>> m_scopeFuncs;
|
||||
/// Variables
|
||||
std::vector<std::vector<std::string>> m_variables;
|
||||
std::vector<std::vector<std::string>> m_globalVars;
|
||||
/// Functions
|
||||
std::vector<std::string> m_functions;
|
||||
/// Maps FunctionDef object to its name
|
||||
|
@ -69,24 +69,17 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
||||
|
||||
// AssemblyStack entry point
|
||||
AssemblyStack stack(
|
||||
langutil::EVMVersion(langutil::EVMVersion::istanbul()),
|
||||
langutil::EVMVersion::istanbul(),
|
||||
AssemblyStack::Language::StrictAssembly,
|
||||
dev::solidity::OptimiserSettings::full()
|
||||
);
|
||||
|
||||
try
|
||||
// Parse protobuf mutated YUL code
|
||||
if (!stack.parseAndAnalyze("source", yul_source) || !stack.parserResult()->code ||
|
||||
!stack.parserResult()->analysisInfo)
|
||||
{
|
||||
// Parse protobuf mutated YUL code
|
||||
if (!stack.parseAndAnalyze("source", yul_source) || !stack.parserResult()->code ||
|
||||
!stack.parserResult()->analysisInfo)
|
||||
{
|
||||
printErrors(std::cout, stack.errors());
|
||||
yulAssert(false, "Proto fuzzer generated malformed program");
|
||||
}
|
||||
}
|
||||
catch (Exception const&)
|
||||
{
|
||||
return;
|
||||
printErrors(std::cout, stack.errors());
|
||||
yulAssert(false, "Proto fuzzer generated malformed program");
|
||||
}
|
||||
|
||||
ostringstream os1;
|
||||
@ -94,7 +87,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
||||
yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret(
|
||||
os1,
|
||||
stack.parserResult()->code,
|
||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion(langutil::EVMVersion::istanbul()))
|
||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion::istanbul())
|
||||
);
|
||||
|
||||
if (termReason == yulFuzzerUtil::TerminationReason::StepLimitReached)
|
||||
@ -104,7 +97,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
||||
termReason = yulFuzzerUtil::interpret(
|
||||
os2,
|
||||
stack.parserResult()->code,
|
||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion(langutil::EVMVersion::istanbul())),
|
||||
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion::istanbul()),
|
||||
(yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 4)
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user