Skip to content

Commit

Permalink
Merge pull request #15228 from ethereum/fix-wrong-native-locations-in…
Browse files Browse the repository at this point in the history
…-ir-optimized-ast

Fix wrong native locations in optimized IR AST
  • Loading branch information
cameel committed Jul 18, 2024
2 parents 91b1254 + 84b89a5 commit 8e74c48
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 139 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Bugfixes:
* SMTChecker: Fix formatting of unary minus expressions in invariants.
* SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine.
* TypeChecker: Fix segfault when assigning nested tuple to tuple.
* Yul AST: Fix ``nativeSrc`` attributes in optimized IR AST referring to locations in unoptimized IR.
* Yul IR Code Generation: Deterministic order of Yul subobjects.
* Yul Optimizer: Name simplification could lead to forbidden identifiers with a leading and/or trailing dot, e.g., ``x._`` would get simplified into ``x.``.
* Yul Parser: Fix segfault when parsing very long location comments.
Expand Down
47 changes: 29 additions & 18 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,25 +1464,36 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
);
}

yul::YulStack stack(
m_evmVersion,
m_eofVersion,
yul::YulStack::Language::StrictAssembly,
m_optimiserSettings,
m_debugInfoSelection
);
bool yulAnalysisSuccessful = stack.parseAndAnalyze("", compiledContract.yulIR);
solAssert(
yulAnalysisSuccessful,
compiledContract.yulIR + "\n\n"
"Invalid IR generated:\n" +
langutil::SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + "\n"
);
auto const parseYul = [&](std::string const& _irSource) {
YulStack stack(
m_evmVersion,
m_eofVersion,
YulStack::Language::StrictAssembly,
m_optimiserSettings,
m_debugInfoSelection
);
bool yulAnalysisSuccessful = stack.parseAndAnalyze("", _irSource);
solAssert(
yulAnalysisSuccessful,
_irSource + "\n\n"
"Invalid IR generated:\n" +
langutil::SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + "\n"
);
return stack;
};

compiledContract.yulIRAst = stack.astJson();
stack.optimize();
compiledContract.yulIROptimized = stack.print(this);
compiledContract.yulIROptimizedAst = stack.astJson();
{
YulStack stack = parseYul(compiledContract.yulIR);
compiledContract.yulIRAst = stack.astJson();
stack.optimize();
compiledContract.yulIROptimized = stack.print(this);
}
{
// Optimizer does not maintain correct native source locations in the AST.
// We can work around it by regenerating the AST from scratch from optimized IR.
YulStack stack = parseYul(compiledContract.yulIROptimized);
compiledContract.yulIROptimizedAst = stack.astJson();
}
}

void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract)
Expand Down
4 changes: 2 additions & 2 deletions libyul/YulStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::yul;
using namespace solidity::langutil;
using namespace solidity::util;

namespace
{
Expand Down Expand Up @@ -257,8 +258,7 @@ MachineAssemblyObject YulStack::assemble(Machine _machine)
case Machine::EVM:
return assembleWithDeployed().first;
}
// unreachable
return MachineAssemblyObject();
unreachable();
}

std::pair<MachineAssemblyObject, MachineAssemblyObject>
Expand Down
2 changes: 0 additions & 2 deletions libyul/YulStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ class YulStack: public langutil::CharStreamProvider
std::shared_ptr<yul::Object> m_parserResult;
langutil::ErrorList m_errors;
langutil::ErrorReporter m_errorReporter;

std::unique_ptr<std::string> m_sourceMappings;
};

}
Loading

0 comments on commit 8e74c48

Please sign in to comment.