diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-08-07 21:16:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-07 21:16:43 +0800 |
commit | 4158a310bde90abe83cb61a071d5c7cdc9064593 (patch) | |
tree | 3a13e6e923ee93fe488788235a32ddc2078fac54 | |
parent | 9d3827266cc734ac91368acff010e094f100f850 (diff) | |
parent | 05cc7e79e1bf484c71ce93510fbfbf2c3e415cc6 (diff) | |
download | dexon-solidity-4158a310bde90abe83cb61a071d5c7cdc9064593.tar.gz dexon-solidity-4158a310bde90abe83cb61a071d5c7cdc9064593.tar.zst dexon-solidity-4158a310bde90abe83cb61a071d5c7cdc9064593.zip |
Merge pull request #4729 from ethereum/slot-on-non-storage
Properly handle invalid references used together with _slot and _offset.
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_function.sol | 9 |
3 files changed, 17 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index e00f74b3..037451ed 100644 --- a/Changelog.md +++ b/Changelog.md @@ -83,6 +83,7 @@ Bugfixes: * Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions. * References Resolver: Do not crash on using ``_slot`` and ``_offset`` suffixes on their own. * References Resolver: Enforce ``storage`` as data location for mappings. + * References Resolver: Properly handle invalid references used together with ``_slot`` and ``_offset``. * References Resolver: Report error instead of assertion fail when FunctionType has an undeclared type as parameter. * Type Checker: Disallow assignments to mappings within tuple assignments as well. * Type Checker: Allow assignments to local variables of mapping types. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 7cec7c43..d98d6af1 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -867,6 +867,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) return size_t(-1); Declaration const* declaration = ref->second.declaration; solAssert(!!declaration, ""); + bool requiresStorage = ref->second.isSlot || ref->second.isOffset; if (auto var = dynamic_cast<VariableDeclaration const*>(declaration)) { if (var->isConstant()) @@ -874,7 +875,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly."); return size_t(-1); } - else if (ref->second.isSlot || ref->second.isOffset) + else if (requiresStorage) { if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage)) { @@ -906,6 +907,11 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) return size_t(-1); } } + else if (requiresStorage) + { + m_errorReporter.typeError(_identifier.location, "The suffixes _offset and _slot can only be used on storage variables."); + return size_t(-1); + } else if (_context == julia::IdentifierContext::LValue) { m_errorReporter.typeError(_identifier.location, "Only local variables can be assigned to in inline assembly."); diff --git a/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_function.sol b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_function.sol new file mode 100644 index 00000000..9165654f --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/storage_reference_on_function.sol @@ -0,0 +1,9 @@ +contract C { + function f() pure public { + assembly { + let x := f_slot + } + } +} +// ---- +// TypeError: (84-90): The suffixes _offset and _slot can only be used on storage variables. |