aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-12 21:02:20 +0800
committerGitHub <noreply@github.com>2017-07-12 21:02:20 +0800
commitfca8d781b4490026dce657fd344a1fe36c9179f2 (patch)
tree3649410bfcc79fcf8221b9094cdc0bd79474506c
parentb981ef2055cd8aa0bb1c6d4a58d547c78c509128 (diff)
parentdb7ad508f8ad33389ae507967aebc05aaf31b94b (diff)
downloaddexon-solidity-fca8d781b4490026dce657fd344a1fe36c9179f2.tar.gz
dexon-solidity-fca8d781b4490026dce657fd344a1fe36c9179f2.tar.zst
dexon-solidity-fca8d781b4490026dce657fd344a1fe36c9179f2.zip
Merge pull request #2556 from ethereum/inlineasm-calldata
Issue proper warning trying to access calldata variables in inline assembly
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp5
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp14
3 files changed, 19 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 9afb0679..075523d7 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,6 +1,7 @@
### 0.4.14 (unreleased)
Features:
+ * Inline Assembly: Show useful error message if trying to access calldata variables.
Bugfixes:
* Type Checker: Fix invalid "specify storage keyword" warning for reference members of structs.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 7306a36d..90043b43 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -723,7 +723,10 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
}
else if (var->type()->sizeOnStack() != 1)
{
- m_errorReporter.typeError(_identifier.location, "Only types that use one stack slot are supported.");
+ if (var->type()->dataStoredIn(DataLocation::CallData))
+ m_errorReporter.typeError(_identifier.location, "Call data elements cannot be accessed directly. Copy to a local variable first or use \"calldataload\" or \"calldatacopy\" with manually determined offsets and sizes.");
+ else
+ m_errorReporter.typeError(_identifier.location, "Only types that use one stack slot are supported.");
return size_t(-1);
}
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 637ff5cc..2ee5baac 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -5428,6 +5428,20 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_variable_access_out_of_functions)
CHECK_SUCCESS_NO_WARNINGS(text);
}
+BOOST_AUTO_TEST_CASE(inline_assembly_calldata_variables)
+{
+ char const* text = R"(
+ contract C {
+ function f(bytes bytesAsCalldata) external {
+ assembly {
+ let x := bytesAsCalldata
+ }
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Call data elements cannot be accessed directly.");
+}
+
BOOST_AUTO_TEST_CASE(invalid_mobile_type)
{
char const* text = R"(