diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2017-05-11 22:57:34 +0800 |
---|---|---|
committer | Rhett Aultman <roadriverrail@gmail.com> | 2017-05-22 06:23:05 +0800 |
commit | 621c3fa22fc5830517ad3174f7ebe2ca67f1f700 (patch) | |
tree | 38effb5a8147855bdb42174cb81443fab21d45f2 | |
parent | 1344f28fdc96276285a009df369e02555141fc27 (diff) | |
download | dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar.gz dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar.bz2 dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar.lz dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar.xz dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.tar.zst dexon-solidity-621c3fa22fc5830517ad3174f7ebe2ca67f1f700.zip |
Analyze InlineAssembly for variable use
The unused variable checker in StaticAnalyzer did not conssider
InlineAssembly objects. This commit introduces that missing feature.
-rw-r--r-- | Changelog.md | 3 | ||||
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.cpp | 25 | ||||
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.h | 1 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 14 |
4 files changed, 41 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md index be5c18c5..9673a057 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### 0.4.12 (unreleased) +Bugfixes: + * Unused variable warnings no longer issued for variables used inside inline assembly + ### 0.4.11 (2017-05-03) Features: diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 369376fa..d273b26e 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -21,14 +21,16 @@ */ #include <libsolidity/analysis/StaticAnalyzer.h> -#include <memory> #include <libsolidity/ast/AST.h> +#include <libsolidity/inlineasm/AsmAnalysis.h> +#include <libsolidity/inlineasm/AsmAnalysisInfo.h> +#include <libsolidity/inlineasm/AsmData.h> +#include <memory> using namespace std; using namespace dev; using namespace dev::solidity; - bool StaticAnalyzer::analyze(SourceUnit const& _sourceUnit) { _sourceUnit.accept(*this); @@ -128,3 +130,22 @@ void StaticAnalyzer::warning(SourceLocation const& _location, string const& _des m_errors.push_back(err); } + +bool StaticAnalyzer::visit(InlineAssembly const& _inlineAssembly) +{ + if (!m_currentFunction) + return true; + + for (auto const& ref: _inlineAssembly.annotation().externalReferences) + { + if (auto var = dynamic_cast<VariableDeclaration const*>(ref.second.declaration)) + { + solAssert(!var->name().empty(), ""); + if (var->isLocalVariable()) + m_localVarUseCount[var] += 1; + } + } + + return true; +} + diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index ab72e7d9..458bab2a 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -65,6 +65,7 @@ private: virtual bool visit(Identifier const& _identifier) override; virtual bool visit(Return const& _return) override; virtual bool visit(MemberAccess const& _memberAccess) override; + virtual bool visit(InlineAssembly const& _inlineAssembly) override; ErrorList& m_errors; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3a9f7295..97c4303f 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5718,6 +5718,20 @@ BOOST_AUTO_TEST_CASE(no_unused_dec_after_use) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(no_unused_inline_asm) +{ + char const* text = R"( + contract C { + function f() { + uint a; + assembly { + a := 1 + } + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} |