aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-02-20 18:17:58 +0800
committerGitHub <noreply@github.com>2018-02-20 18:17:58 +0800
commita6b52fdc34650c74597c1bcdc5075b6375c62650 (patch)
tree93a9f3fe5139033e4c858adccaa635db1ed73a76
parent2a58b44b8bdb802747ea6b908350cfb61dc75bb9 (diff)
parent83692360b1a3213fbe8a65b08b892980312b7ac1 (diff)
downloaddexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar.gz
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar.bz2
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar.lz
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar.xz
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.tar.zst
dexon-solidity-a6b52fdc34650c74597c1bcdc5075b6375c62650.zip
Merge pull request #3550 from ethereum/offsetconstantsasm
Properly warn when using ``_offset`` and ``_slot`` for constants in inline assembly.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp12
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp15
3 files changed, 22 insertions, 6 deletions
diff --git a/Changelog.md b/Changelog.md
index de0b742e..d6b83d6e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@ Features:
Bugfixes:
* JSON-AST: Add "documentation" property to function, event and modifier definition.
* Standard JSON: catch errors properly when invalid "sources" are passed
+ * Type Checker: Properly warn when using ``_offset`` and ``_slot`` for constants in inline assembly.
### 0.4.20 (2018-02-14)
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index f62ddeb9..0ee16c89 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -804,7 +804,12 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
solAssert(!!declaration, "");
if (auto var = dynamic_cast<VariableDeclaration const*>(declaration))
{
- if (ref->second.isSlot || ref->second.isOffset)
+ if (var->isConstant())
+ {
+ m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly.");
+ return size_t(-1);
+ }
+ else if (ref->second.isSlot || ref->second.isOffset)
{
if (!var->isStateVariable() && !var->type()->dataStoredIn(DataLocation::Storage))
{
@@ -817,11 +822,6 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
return size_t(-1);
}
}
- else if (var->isConstant())
- {
- m_errorReporter.typeError(_identifier.location, "Constant variables not supported by inline assembly.");
- return size_t(-1);
- }
else if (!var->isLocalVariable())
{
m_errorReporter.typeError(_identifier.location, "Only local variables are supported. To access storage variables, use the _slot and _offset suffixes.");
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2b102312..7c03d7cb 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -5776,6 +5776,21 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_variable_access_out_of_functions)
CHECK_SUCCESS_NO_WARNINGS(text);
}
+BOOST_AUTO_TEST_CASE(inline_assembly_constant_variable_via_offset)
+{
+ char const* text = R"(
+ contract test {
+ uint constant x = 2;
+ function f() pure public {
+ assembly {
+ let r := x_offset
+ }
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly.");
+}
+
BOOST_AUTO_TEST_CASE(inline_assembly_calldata_variables)
{
char const* text = R"(