mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fixes segfault on empty contract w/ error recovery.
This commit is contained in:
parent
0620936506
commit
cc1b28b12e
@ -281,30 +281,31 @@ bool CompilerStack::analyze()
|
||||
{
|
||||
SyntaxChecker syntaxChecker(m_errorReporter, m_optimiserSettings.runYulOptimiser);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!syntaxChecker.checkSyntax(*source->ast))
|
||||
if (source->ast && !syntaxChecker.checkSyntax(*source->ast))
|
||||
noErrors = false;
|
||||
|
||||
DocStringAnalyser docStringAnalyser(m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!docStringAnalyser.analyseDocStrings(*source->ast))
|
||||
if (source->ast && !docStringAnalyser.analyseDocStrings(*source->ast))
|
||||
noErrors = false;
|
||||
|
||||
m_globalContext = make_shared<GlobalContext>();
|
||||
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_scopes, m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!resolver.registerDeclarations(*source->ast))
|
||||
if (source->ast && !resolver.registerDeclarations(*source->ast))
|
||||
return false;
|
||||
|
||||
map<string, SourceUnit const*> sourceUnitsByName;
|
||||
for (auto& source: m_sources)
|
||||
sourceUnitsByName[source.first] = source.second.ast.get();
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!resolver.performImports(*source->ast, sourceUnitsByName))
|
||||
if (source->ast && !resolver.performImports(*source->ast, sourceUnitsByName))
|
||||
return false;
|
||||
|
||||
// This is the main name and type resolution loop. Needs to be run for every contract, because
|
||||
// the special variables "this" and "super" must be set appropriately.
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (source->ast)
|
||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||
{
|
||||
if (!resolver.resolveNamesAndTypes(*node))
|
||||
@ -324,6 +325,7 @@ bool CompilerStack::analyze()
|
||||
// type checker.
|
||||
ContractLevelChecker contractLevelChecker(m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (source->ast)
|
||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||
if (!contractLevelChecker.check(*contract))
|
||||
@ -338,6 +340,7 @@ bool CompilerStack::analyze()
|
||||
// which is only done one step later.
|
||||
TypeChecker typeChecker(m_evmVersion, m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (source->ast)
|
||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||
if (!typeChecker.checkTypeRequirements(*contract))
|
||||
@ -348,7 +351,7 @@ bool CompilerStack::analyze()
|
||||
// Checks that can only be done when all types of all AST nodes are known.
|
||||
PostTypeChecker postTypeChecker(m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!postTypeChecker.check(*source->ast))
|
||||
if (source->ast && !postTypeChecker.check(*source->ast))
|
||||
noErrors = false;
|
||||
}
|
||||
|
||||
@ -358,14 +361,14 @@ bool CompilerStack::analyze()
|
||||
// variable is used before it is assigned to.
|
||||
CFG cfg(m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!cfg.constructFlow(*source->ast))
|
||||
if (source->ast && !cfg.constructFlow(*source->ast))
|
||||
noErrors = false;
|
||||
|
||||
if (noErrors)
|
||||
{
|
||||
ControlFlowAnalyzer controlFlowAnalyzer(cfg, m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!controlFlowAnalyzer.analyze(*source->ast))
|
||||
if (source->ast && !controlFlowAnalyzer.analyze(*source->ast))
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
@ -375,7 +378,7 @@ bool CompilerStack::analyze()
|
||||
// Checks for common mistakes. Only generates warnings.
|
||||
StaticAnalyzer staticAnalyzer(m_errorReporter);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (!staticAnalyzer.analyze(*source->ast))
|
||||
if (source->ast && !staticAnalyzer.analyze(*source->ast))
|
||||
noErrors = false;
|
||||
}
|
||||
|
||||
@ -384,6 +387,7 @@ bool CompilerStack::analyze()
|
||||
// Check for state mutability in every function.
|
||||
vector<ASTPointer<ASTNode>> ast;
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (source->ast)
|
||||
ast.push_back(source->ast);
|
||||
|
||||
if (!ViewPureChecker(ast, m_errorReporter).check())
|
||||
@ -394,6 +398,7 @@ bool CompilerStack::analyze()
|
||||
{
|
||||
ModelChecker modelChecker(m_errorReporter, m_smtlib2Responses, m_readFile, m_enabledSMTSolvers);
|
||||
for (Source const* source: m_sourceOrder)
|
||||
if (source->ast)
|
||||
modelChecker.analyze(*source->ast);
|
||||
m_unhandledSMTLib2Queries += modelChecker.unhandledQueries();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user