aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-11 22:13:41 +0800
committerGitHub <noreply@github.com>2018-04-11 22:13:41 +0800
commitc9bdbcf470f4ca7f8d2d71f1be180274f534888d (patch)
treec2e87c1f85164bf7631e22c2ec53f9fd7bed681c /libsolidity
parentb7b6d0ce7c0c01a3600421ee3a402b1c913d8892 (diff)
parent43d2954de83af5f64f526fd36f1cd5c3b5299498 (diff)
downloaddexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar.gz
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar.bz2
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar.lz
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar.xz
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.tar.zst
dexon-solidity-c9bdbcf470f4ca7f8d2d71f1be180274f534888d.zip
Merge pull request #3309 from ethereum/limit-errors
Limit the number of errors output in a single run to 256
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp12
-rw-r--r--libsolidity/interface/CompilerStack.cpp143
-rw-r--r--libsolidity/interface/ErrorReporter.cpp37
-rw-r--r--libsolidity/interface/ErrorReporter.h9
4 files changed, 123 insertions, 78 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index abe57778..8b57fc15 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -60,17 +60,7 @@ bool typeSupportedByOldABIEncoder(Type const& _type)
bool TypeChecker::checkTypeRequirements(ASTNode const& _contract)
{
- try
- {
- _contract.accept(*this);
- }
- catch (FatalError const&)
- {
- // We got a fatal error which required to stop further type checking, but we can
- // continue normally from here.
- if (m_errorReporter.errors().empty())
- throw; // Something is weird here, rather throw again.
- }
+ _contract.accept(*this);
return Error::containsOnlyWarnings(m_errorReporter.errors());
}
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index eacfca9c..4ff14aa2 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -164,85 +164,94 @@ bool CompilerStack::analyze()
resolveImports();
bool noErrors = true;
- SyntaxChecker syntaxChecker(m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!syntaxChecker.checkSyntax(*source->ast))
- noErrors = false;
-
- DocStringAnalyser docStringAnalyser(m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!docStringAnalyser.analyseDocStrings(*source->ast))
- noErrors = false;
- m_globalContext = make_shared<GlobalContext>();
- NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!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))
- return false;
+ try {
+ SyntaxChecker syntaxChecker(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!syntaxChecker.checkSyntax(*source->ast))
+ noErrors = false;
- for (Source const* source: m_sourceOrder)
- for (ASTPointer<ASTNode> const& node: source->ast->nodes())
- if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
- {
- m_globalContext->setCurrentContract(*contract);
- if (!resolver.updateDeclaration(*m_globalContext->currentThis())) return false;
- if (!resolver.updateDeclaration(*m_globalContext->currentSuper())) return false;
- if (!resolver.resolveNamesAndTypes(*contract)) return false;
-
- // Note that we now reference contracts by their fully qualified names, and
- // thus contracts can only conflict if declared in the same source file. This
- // already causes a double-declaration error elsewhere, so we do not report
- // an error here and instead silently drop any additional contracts we find.
-
- if (m_contracts.find(contract->fullyQualifiedName()) == m_contracts.end())
- m_contracts[contract->fullyQualifiedName()].contract = contract;
- }
+ DocStringAnalyser docStringAnalyser(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!docStringAnalyser.analyseDocStrings(*source->ast))
+ noErrors = false;
- TypeChecker typeChecker(m_evmVersion, m_errorReporter);
- for (Source const* source: m_sourceOrder)
- for (ASTPointer<ASTNode> const& node: source->ast->nodes())
- if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
- if (!typeChecker.checkTypeRequirements(*contract))
- noErrors = false;
+ m_globalContext = make_shared<GlobalContext>();
+ NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!resolver.registerDeclarations(*source->ast))
+ return false;
- if (noErrors)
- {
- PostTypeChecker postTypeChecker(m_errorReporter);
+ map<string, SourceUnit const*> sourceUnitsByName;
+ for (auto& source: m_sources)
+ sourceUnitsByName[source.first] = source.second.ast.get();
for (Source const* source: m_sourceOrder)
- if (!postTypeChecker.check(*source->ast))
- noErrors = false;
- }
+ if (!resolver.performImports(*source->ast, sourceUnitsByName))
+ return false;
- if (noErrors)
- {
- StaticAnalyzer staticAnalyzer(m_errorReporter);
for (Source const* source: m_sourceOrder)
- if (!staticAnalyzer.analyze(*source->ast))
- noErrors = false;
- }
+ for (ASTPointer<ASTNode> const& node: source->ast->nodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ m_globalContext->setCurrentContract(*contract);
+ if (!resolver.updateDeclaration(*m_globalContext->currentThis())) return false;
+ if (!resolver.updateDeclaration(*m_globalContext->currentSuper())) return false;
+ if (!resolver.resolveNamesAndTypes(*contract)) return false;
+
+ // Note that we now reference contracts by their fully qualified names, and
+ // thus contracts can only conflict if declared in the same source file. This
+ // already causes a double-declaration error elsewhere, so we do not report
+ // an error here and instead silently drop any additional contracts we find.
+
+ if (m_contracts.find(contract->fullyQualifiedName()) == m_contracts.end())
+ m_contracts[contract->fullyQualifiedName()].contract = contract;
+ }
- if (noErrors)
- {
- vector<ASTPointer<ASTNode>> ast;
+ TypeChecker typeChecker(m_evmVersion, m_errorReporter);
for (Source const* source: m_sourceOrder)
- ast.push_back(source->ast);
+ for (ASTPointer<ASTNode> const& node: source->ast->nodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ if (!typeChecker.checkTypeRequirements(*contract))
+ noErrors = false;
- if (!ViewPureChecker(ast, m_errorReporter).check())
- noErrors = false;
- }
+ if (noErrors)
+ {
+ PostTypeChecker postTypeChecker(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!postTypeChecker.check(*source->ast))
+ noErrors = false;
+ }
- if (noErrors)
+ if (noErrors)
+ {
+ StaticAnalyzer staticAnalyzer(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!staticAnalyzer.analyze(*source->ast))
+ noErrors = false;
+ }
+
+ if (noErrors)
+ {
+ vector<ASTPointer<ASTNode>> ast;
+ for (Source const* source: m_sourceOrder)
+ ast.push_back(source->ast);
+
+ if (!ViewPureChecker(ast, m_errorReporter).check())
+ noErrors = false;
+ }
+
+ if (noErrors)
+ {
+ SMTChecker smtChecker(m_errorReporter, m_smtQuery);
+ for (Source const* source: m_sourceOrder)
+ smtChecker.analyze(*source->ast);
+ }
+ }
+ catch(FatalError const&)
{
- SMTChecker smtChecker(m_errorReporter, m_smtQuery);
- for (Source const* source: m_sourceOrder)
- smtChecker.analyze(*source->ast);
+ if (m_errorReporter.errors().empty())
+ throw; // Something is weird here, rather throw again.
+ noErrors = false;
}
if (noErrors)
diff --git a/libsolidity/interface/ErrorReporter.cpp b/libsolidity/interface/ErrorReporter.cpp
index e6171756..368e25e0 100644
--- a/libsolidity/interface/ErrorReporter.cpp
+++ b/libsolidity/interface/ErrorReporter.cpp
@@ -61,6 +61,9 @@ void ErrorReporter::warning(
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, string const& _description)
{
+ if (checkForExcessiveErrors(_type))
+ return;
+
auto err = make_shared<Error>(_type);
*err <<
errinfo_sourceLocation(_location) <<
@@ -71,6 +74,9 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, st
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{
+ if (checkForExcessiveErrors(_type))
+ return;
+
auto err = make_shared<Error>(_type);
*err <<
errinfo_sourceLocation(_location) <<
@@ -80,6 +86,37 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, Se
m_errorList.push_back(err);
}
+bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
+{
+ if (_type == Error::Type::Warning)
+ {
+ m_warningCount++;
+
+ if (m_warningCount == c_maxWarningsAllowed)
+ {
+ auto err = make_shared<Error>(Error::Type::Warning);
+ *err << errinfo_comment("There are more than 256 warnings. Ignoring the rest.");
+ m_errorList.push_back(err);
+ }
+
+ if (m_warningCount >= c_maxWarningsAllowed)
+ return true;
+ }
+ else
+ {
+ m_errorCount++;
+
+ if (m_errorCount > c_maxErrorsAllowed)
+ {
+ auto err = make_shared<Error>(Error::Type::Warning);
+ *err << errinfo_comment("There are more than 256 errors. Aborting.");
+ m_errorList.push_back(err);
+ BOOST_THROW_EXCEPTION(FatalError());
+ }
+ }
+
+ return false;
+}
void ErrorReporter::fatalError(Error::Type _type, SourceLocation const& _location, string const& _description)
{
diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h
index a87db21d..d1a0030f 100644
--- a/libsolidity/interface/ErrorReporter.h
+++ b/libsolidity/interface/ErrorReporter.h
@@ -102,7 +102,16 @@ private:
SourceLocation const& _location = SourceLocation(),
std::string const& _description = std::string());
+ // @returns true if error shouldn't be stored
+ bool checkForExcessiveErrors(Error::Type _type);
+
ErrorList& m_errorList;
+
+ unsigned m_errorCount = 0;
+ unsigned m_warningCount = 0;
+
+ const unsigned c_maxWarningsAllowed = 256;
+ const unsigned c_maxErrorsAllowed = 256;
};