2022-02-10 16:57:43 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
#include <test/libsolidity/MemoryGuardTest.h>
|
|
|
|
|
|
|
|
#include <test/libyul/Common.h>
|
|
|
|
#include <libsolidity/codegen/ir/Common.h>
|
|
|
|
#include <libsolutil/Algorithms.h>
|
|
|
|
#include <libyul/Object.h>
|
|
|
|
#include <libyul/backends/evm/EVMDialect.h>
|
|
|
|
#include <libyul/optimiser/FunctionCallFinder.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::util::formatting;
|
|
|
|
using namespace solidity::langutil;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
using namespace solidity::frontend::test;
|
|
|
|
using namespace yul;
|
|
|
|
|
2023-08-07 11:00:08 +00:00
|
|
|
void MemoryGuardTest::setupCompiler(CompilerStack& _compiler)
|
|
|
|
{
|
2023-08-07 10:26:44 +00:00
|
|
|
AnalysisFramework::setupCompiler(_compiler);
|
|
|
|
|
2023-08-07 11:00:08 +00:00
|
|
|
_compiler.setViaIR(true);
|
|
|
|
_compiler.setOptimiserSettings(OptimiserSettings::none());
|
|
|
|
}
|
|
|
|
|
2023-08-30 00:08:06 +00:00
|
|
|
TestCase::TestResult MemoryGuardTest::run(std::ostream& _stream, std::string const& _linePrefix, bool _formatted)
|
2022-02-10 16:57:43 +00:00
|
|
|
{
|
2023-08-07 11:00:08 +00:00
|
|
|
if (!runFramework(m_source, PipelineStage::Compilation))
|
2023-08-04 13:27:27 +00:00
|
|
|
{
|
|
|
|
_stream << formatErrors(filteredErrors(), _formatted);
|
2022-02-10 16:57:43 +00:00
|
|
|
return TestResult::FatalError;
|
2023-08-04 13:27:27 +00:00
|
|
|
}
|
2022-02-10 16:57:43 +00:00
|
|
|
|
|
|
|
m_obtainedResult.clear();
|
2023-08-30 00:08:06 +00:00
|
|
|
for (std::string contractName: compiler().contractNames())
|
2022-02-10 16:57:43 +00:00
|
|
|
{
|
|
|
|
ErrorList errors;
|
|
|
|
auto [object, analysisInfo] = yul::test::parse(
|
|
|
|
compiler().yulIR(contractName),
|
|
|
|
EVMDialect::strictAssemblyForEVMObjects({}),
|
|
|
|
errors
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!object || !analysisInfo || Error::containsErrors(errors))
|
|
|
|
{
|
2023-08-30 00:08:06 +00:00
|
|
|
AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Error parsing IR." << std::endl;
|
2022-02-10 16:57:43 +00:00
|
|
|
return TestResult::FatalError;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto handleObject = [&](std::string const& _kind, Object const& _object) {
|
|
|
|
m_obtainedResult += contractName + "(" + _kind + ") " + (FunctionCallFinder::run(
|
|
|
|
*_object.code,
|
|
|
|
"memoryguard"_yulstring
|
|
|
|
).empty() ? "false" : "true") + "\n";
|
|
|
|
};
|
|
|
|
handleObject("creation", *object);
|
|
|
|
size_t deployedIndex = object->subIndexByName.at(
|
|
|
|
YulString(IRNames::deployedObject(compiler().contractDefinition(contractName)))
|
|
|
|
);
|
|
|
|
handleObject("runtime", dynamic_cast<Object const&>(*object->subObjects[deployedIndex]));
|
|
|
|
}
|
|
|
|
return checkResult(_stream, _linePrefix, _formatted);
|
|
|
|
}
|