diff options
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ReferencesResolver.cpp | 20 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 25 |
2 files changed, 38 insertions, 7 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index a50fc6a0..2b40b4fd 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -28,6 +28,8 @@ #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmData.h> +#include <boost/algorithm/string.hpp> + using namespace std; using namespace dev; using namespace dev::solidity; @@ -166,10 +168,26 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) assembly::ExternalIdentifierAccess::Resolver resolver = [&](assembly::Identifier const& _identifier, assembly::IdentifierContext) { auto declarations = m_resolver.nameFromCurrentScope(_identifier.name); + bool isSlot = boost::algorithm::ends_with(_identifier.name, "_slot"); + bool isOffset = boost::algorithm::ends_with(_identifier.name, "_offset"); + if (isSlot || isOffset) + { + // special mode to access storage variables + if (!declarations.empty()) + // the special identifier exists itself, we should not allow that. + return size_t(-1); + string realName = _identifier.name.substr(0, + _identifier.name.size() - isSlot ? + string("_slot").size() : + string("_offset").size() + ); + declarations = m_resolver.nameFromCurrentScope(realName); + } if (declarations.size() != 1) return size_t(-1); + _inlineAssembly.annotation().externalReferences[&_identifier].isSlot = isSlot; + _inlineAssembly.annotation().externalReferences[&_identifier].isOffset = isOffset; _inlineAssembly.annotation().externalReferences[&_identifier].declaration = declarations.front(); - // At this stage we do not yet know the stack size of the identifier, so we just return 1. return size_t(1); }; assembly::AsmAnalyzer::Scopes scopes; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 29011676..b07dbde1 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -642,22 +642,35 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) solAssert(!!declaration, ""); if (auto var = dynamic_cast<VariableDeclaration const*>(declaration)) { - if (!var->isLocalVariable()) + if (ref->second.isSlot || ref->second.isOffset) { - typeError(_identifier.location, "Only local variables are supported."); + if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage)) + { + typeError(_identifier.location, "The suffixes _offset and _slot can only be used on storage variables."); + return size_t(-1); + } + else if (_context != assembly::IdentifierContext::RValue) + { + typeError(_identifier.location, "Storage variables cannot be assigned to."); + return size_t(-1); + } + } + else if (!var->isLocalVariable()) + { + typeError(_identifier.location, "Only local variables are supported. To access storage variables, use the _slot and _offset suffixes."); return size_t(-1); } - if (var->type()->dataStoredIn(DataLocation::Storage)) + else if (var->type()->dataStoredIn(DataLocation::Storage)) { - typeError(_identifier.location, "Storage reference variables are not supported."); + typeError(_identifier.location, "You have to use the _slot or _offset prefix to access storage reference variables."); return size_t(-1); } - if (var->type()->sizeOnStack() != 1) + else if (var->type()->sizeOnStack() != 1) { typeError(_identifier.location, "Only types that use one stack slot are supported."); return size_t(-1); } - if (var->isConstant()) + else if (var->isConstant()) { typeError(_identifier.location, "Constant variables not supported by inline assembly."); return size_t(-1); |