mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7961 from ethereum/error-recovery-ast-segfault
Fix segfault on empty contract compiled w/ --error-recovery
This commit is contained in:
commit
800090e850
@ -281,30 +281,31 @@ bool CompilerStack::analyze()
|
|||||||
{
|
{
|
||||||
SyntaxChecker syntaxChecker(m_errorReporter, m_optimiserSettings.runYulOptimiser);
|
SyntaxChecker syntaxChecker(m_errorReporter, m_optimiserSettings.runYulOptimiser);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!syntaxChecker.checkSyntax(*source->ast))
|
if (source->ast && !syntaxChecker.checkSyntax(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
|
|
||||||
DocStringAnalyser docStringAnalyser(m_errorReporter);
|
DocStringAnalyser docStringAnalyser(m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!docStringAnalyser.analyseDocStrings(*source->ast))
|
if (source->ast && !docStringAnalyser.analyseDocStrings(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
|
|
||||||
m_globalContext = make_shared<GlobalContext>();
|
m_globalContext = make_shared<GlobalContext>();
|
||||||
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_scopes, m_errorReporter);
|
NameAndTypeResolver resolver(*m_globalContext, m_evmVersion, m_scopes, m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!resolver.registerDeclarations(*source->ast))
|
if (source->ast && !resolver.registerDeclarations(*source->ast))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
map<string, SourceUnit const*> sourceUnitsByName;
|
map<string, SourceUnit const*> sourceUnitsByName;
|
||||||
for (auto& source: m_sources)
|
for (auto& source: m_sources)
|
||||||
sourceUnitsByName[source.first] = source.second.ast.get();
|
sourceUnitsByName[source.first] = source.second.ast.get();
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!resolver.performImports(*source->ast, sourceUnitsByName))
|
if (source->ast && !resolver.performImports(*source->ast, sourceUnitsByName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// This is the main name and type resolution loop. Needs to be run for every contract, because
|
// 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.
|
// the special variables "this" and "super" must be set appropriately.
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
if (source->ast)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
{
|
{
|
||||||
if (!resolver.resolveNamesAndTypes(*node))
|
if (!resolver.resolveNamesAndTypes(*node))
|
||||||
@ -324,6 +325,7 @@ bool CompilerStack::analyze()
|
|||||||
// type checker.
|
// type checker.
|
||||||
ContractLevelChecker contractLevelChecker(m_errorReporter);
|
ContractLevelChecker contractLevelChecker(m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
if (source->ast)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
if (!contractLevelChecker.check(*contract))
|
if (!contractLevelChecker.check(*contract))
|
||||||
@ -338,6 +340,7 @@ bool CompilerStack::analyze()
|
|||||||
// which is only done one step later.
|
// which is only done one step later.
|
||||||
TypeChecker typeChecker(m_evmVersion, m_errorReporter);
|
TypeChecker typeChecker(m_evmVersion, m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
if (source->ast)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
if (!typeChecker.checkTypeRequirements(*contract))
|
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.
|
// Checks that can only be done when all types of all AST nodes are known.
|
||||||
PostTypeChecker postTypeChecker(m_errorReporter);
|
PostTypeChecker postTypeChecker(m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!postTypeChecker.check(*source->ast))
|
if (source->ast && !postTypeChecker.check(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,14 +361,14 @@ bool CompilerStack::analyze()
|
|||||||
// variable is used before it is assigned to.
|
// variable is used before it is assigned to.
|
||||||
CFG cfg(m_errorReporter);
|
CFG cfg(m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!cfg.constructFlow(*source->ast))
|
if (source->ast && !cfg.constructFlow(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
|
|
||||||
if (noErrors)
|
if (noErrors)
|
||||||
{
|
{
|
||||||
ControlFlowAnalyzer controlFlowAnalyzer(cfg, m_errorReporter);
|
ControlFlowAnalyzer controlFlowAnalyzer(cfg, m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!controlFlowAnalyzer.analyze(*source->ast))
|
if (source->ast && !controlFlowAnalyzer.analyze(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -375,7 +378,7 @@ bool CompilerStack::analyze()
|
|||||||
// Checks for common mistakes. Only generates warnings.
|
// Checks for common mistakes. Only generates warnings.
|
||||||
StaticAnalyzer staticAnalyzer(m_errorReporter);
|
StaticAnalyzer staticAnalyzer(m_errorReporter);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
if (!staticAnalyzer.analyze(*source->ast))
|
if (source->ast && !staticAnalyzer.analyze(*source->ast))
|
||||||
noErrors = false;
|
noErrors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,6 +387,7 @@ bool CompilerStack::analyze()
|
|||||||
// Check for state mutability in every function.
|
// Check for state mutability in every function.
|
||||||
vector<ASTPointer<ASTNode>> ast;
|
vector<ASTPointer<ASTNode>> ast;
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
if (source->ast)
|
||||||
ast.push_back(source->ast);
|
ast.push_back(source->ast);
|
||||||
|
|
||||||
if (!ViewPureChecker(ast, m_errorReporter).check())
|
if (!ViewPureChecker(ast, m_errorReporter).check())
|
||||||
@ -394,6 +398,7 @@ bool CompilerStack::analyze()
|
|||||||
{
|
{
|
||||||
ModelChecker modelChecker(m_errorReporter, m_smtlib2Responses, m_readFile, m_enabledSMTSolvers);
|
ModelChecker modelChecker(m_errorReporter, m_smtlib2Responses, m_readFile, m_enabledSMTSolvers);
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
|
if (source->ast)
|
||||||
modelChecker.analyze(*source->ast);
|
modelChecker.analyze(*source->ast);
|
||||||
m_unhandledSMTLib2Queries += modelChecker.unhandledQueries();
|
m_unhandledSMTLib2Queries += modelChecker.unhandledQueries();
|
||||||
}
|
}
|
||||||
|
1
test/cmdlineTests/recovery_ast_empty_contract/args
Normal file
1
test/cmdlineTests/recovery_ast_empty_contract/args
Normal file
@ -0,0 +1 @@
|
|||||||
|
--error-recovery
|
8
test/cmdlineTests/recovery_ast_empty_contract/err
Normal file
8
test/cmdlineTests/recovery_ast_empty_contract/err
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Error: Expected pragma, import directive or contract/interface/library/struct/enum definition.
|
||||||
|
--> recovery_ast_empty_contract/input.sol:2:1:
|
||||||
|
|
|
||||||
|
2 | c
|
||||||
|
| ^
|
||||||
|
|
||||||
|
|
||||||
|
Compilation halted after AST generation due to errors.
|
2
test/cmdlineTests/recovery_ast_empty_contract/input.sol
Normal file
2
test/cmdlineTests/recovery_ast_empty_contract/input.sol
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pragma 0.5.11;
|
||||||
|
c
|
Loading…
Reference in New Issue
Block a user