diff --git a/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp b/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp index 11814574a..ee274a72b 100644 --- a/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp +++ b/test/tools/ossfuzz/SolidityCustomMutatorInterface.cpp @@ -53,9 +53,10 @@ SolidityCustomMutatorInterface::SolidityCustomMutatorInterface( ): data(_data), size(_size), - maxMutantSize(_maxSize), - generator(make_shared(_seed)) -{} + maxMutantSize(_maxSize) +{ + generator = make_shared(_seed); +} size_t SolidityCustomMutatorInterface::generate() { diff --git a/test/tools/ossfuzz/SolidityGenerator.cpp b/test/tools/ossfuzz/SolidityGenerator.cpp index 3a3f80603..f93108c55 100644 --- a/test/tools/ossfuzz/SolidityGenerator.cpp +++ b/test/tools/ossfuzz/SolidityGenerator.cpp @@ -33,10 +33,9 @@ using namespace solidity::test::fuzzer::mutator; using namespace solidity::util; using namespace std; -GeneratorBase::GeneratorBase(SolidityGenerator* _mutator) +GeneratorBase::GeneratorBase(SolidityGenerator* _mutator): state(_mutator->testState()) { mutator = _mutator; - state = mutator->testState(); } string GeneratorBase::visitChildren() diff --git a/test/tools/ossfuzz/SolidityGenerator.h b/test/tools/ossfuzz/SolidityGenerator.h index ae3a40bbe..923ff1bee 100644 --- a/test/tools/ossfuzz/SolidityGenerator.h +++ b/test/tools/ossfuzz/SolidityGenerator.h @@ -347,10 +347,10 @@ struct FunctionState; struct SourceState { explicit SourceState( - std::shared_ptr _urd, + std::shared_ptr& _urd, std::string _sourceName ): - uRandDist(std::move(_urd)), + uRandDist(_urd), importedSources({}), sourceName(_sourceName) {} @@ -417,7 +417,7 @@ struct SourceState } /// Prints source state to @param _os. void print(std::ostream& _os) const; - std::shared_ptr uRandDist; + std::shared_ptr& uRandDist; std::set importedSources; std::map exports; std::set> freeFunctions; @@ -485,10 +485,10 @@ struct FunctionState struct ContractState { explicit ContractState( - std::shared_ptr _urd, + std::shared_ptr& _urd, std::string _contractName ): - uRandDist(std::move(_urd)), + uRandDist(_urd), name(_contractName) {} ~ContractState() @@ -502,19 +502,19 @@ struct ContractState } std::set> functions; - std::shared_ptr uRandDist; + std::shared_ptr& uRandDist; std::string name; }; struct TestState { - explicit TestState(std::shared_ptr _urd): + explicit TestState(std::shared_ptr& _urd): sourceUnitState({}), contractState({}), currentSourceUnitPath({}), currentContract({}), currentFunction({}), - uRandDist(std::move(_urd)), + uRandDist(_urd), numSourceUnits(0), numContracts(0), numFunctions(0), @@ -673,7 +673,7 @@ struct TestState /// Current function std::string currentFunction; /// Uniform random distribution. - std::shared_ptr uRandDist; + std::shared_ptr& uRandDist; /// Number of source units in test input size_t numSourceUnits; /// Number of contracts in test input @@ -694,14 +694,9 @@ struct TestState struct TypeProvider { - TypeProvider(std::shared_ptr _state): state(std::move(_state)) + TypeProvider(std::shared_ptr& _state): state(_state) {} - ~TypeProvider() - { - state.reset(); - } - enum class Type: size_t { INTEGER = 1, @@ -722,7 +717,7 @@ struct TypeProvider return static_cast(state->uRandDist->distributionOneToN(static_cast(Type::TYPEMAX) - 1)); } - std::shared_ptr state; + std::shared_ptr& state; }; struct TypeComparator @@ -743,14 +738,9 @@ struct TypeComparator struct LiteralGenerator { - explicit LiteralGenerator(std::shared_ptr _state): state(std::move(_state)) + explicit LiteralGenerator(std::shared_ptr& _state): state(_state) {} - ~LiteralGenerator() - { - state.reset(); - } - std::string operator()(std::shared_ptr const& _type); std::string operator()(std::shared_ptr const& _type); std::string operator()(std::shared_ptr const& _type); @@ -759,19 +749,14 @@ struct LiteralGenerator std::string operator()(std::shared_ptr const& _type); std::string operator()(std::shared_ptr const& _type); - std::shared_ptr state; + std::shared_ptr& state; }; struct ExpressionGenerator { - ExpressionGenerator(std::shared_ptr _state): state(std::move(_state)) + ExpressionGenerator(std::shared_ptr& _state): state(_state) {} - ~ExpressionGenerator() - { - state.reset(); - } - enum class RLValueExpr: size_t { VARREF = 1, @@ -847,7 +832,7 @@ struct ExpressionGenerator { return nestingDepth > s_maxNestingDepth; } - std::shared_ptr state; + std::shared_ptr& state; unsigned nestingDepth; static constexpr unsigned s_maxNestingDepth = 30; }; @@ -869,14 +854,14 @@ public: std::shared_ptr generator(); /// @returns a shared ptr to underlying random /// number distribution. - std::shared_ptr uniformRandomDist() + std::shared_ptr& uniformRandomDist() { return m_urd; } /// @returns a pseudo randomly generated test case. std::string generateTestProgram(); /// @returns shared ptr to global test state. - std::shared_ptr testState() + std::shared_ptr& testState() { return m_state; } @@ -946,9 +931,8 @@ struct GeneratorBase virtual ~GeneratorBase() { generators.clear(); - state.reset(); } - std::shared_ptr uRandDist() + std::shared_ptr& uRandDist() { return mutator->uniformRandomDist(); } @@ -958,7 +942,7 @@ struct GeneratorBase /// Set of generators used by this generator. std::set> generators; /// Shared ptr to global test state. - std::shared_ptr state; + std::shared_ptr& state; }; class TestCaseGenerator: public GeneratorBase