From 51cd87c94d0fa2374551e92a0368db60891491e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 15 May 2023 14:20:56 +0200 Subject: [PATCH] YulStack: Don't enable stack optimizations in unoptimized mode when msize is present --- libyul/YulStack.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libyul/YulStack.cpp b/libyul/YulStack.cpp index cc8fbc589..66acc3f60 100644 --- a/libyul/YulStack.cpp +++ b/libyul/YulStack.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,13 @@ bool YulStack::parseAndAnalyze(std::string const& _sourceName, std::string const void YulStack::optimize() { yulAssert(m_analysisSuccessful, "Analysis was not successful."); + yulAssert(m_parserResult); + + if ( + !m_optimiserSettings.runYulOptimiser && + yul::MSizeFinder::containsMSize(languageToDialect(m_language, m_evmVersion), *m_parserResult) + ) + return; m_analysisSuccessful = false; yulAssert(m_parserResult, ""); @@ -231,10 +239,13 @@ YulStack::assembleEVMWithDeployed(optional _deployName) const evmasm::Assembly assembly(m_evmVersion, true, {}); EthAssemblyAdapter adapter(assembly); - // NOTE: We always need stack optimization when Yul optimizer is disabled. It being disabled - // just means that we don't use the full step sequence. We still run it with the minimal steps - // required to avoid "stack too deep". - bool optimize = m_optimiserSettings.optimizeStackAllocation || !m_optimiserSettings.runYulOptimiser; + // NOTE: We always need stack optimization when Yul optimizer is disabled (unless code contains + // msize). It being disabled just means that we don't use the full step sequence. We still run + // it with the minimal steps required to avoid "stack too deep". + bool optimize = m_optimiserSettings.optimizeStackAllocation || ( + !m_optimiserSettings.runYulOptimiser && + !yul::MSizeFinder::containsMSize(languageToDialect(m_language, m_evmVersion), *m_parserResult) + ); compileEVM(adapter, optimize); assembly.optimise(evmasm::Assembly::OptimiserSettings::translateSettings(m_optimiserSettings, m_evmVersion));