Skip to content

Commit

Permalink
Add a warning about returndatasize
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Jun 9, 2017
1 parent 7b5e621 commit 6545b4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions libsolidity/analysis/NameAndTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ vector<Declaration const*> NameAndTypeResolver::cleanedDeclarations(
return uniqueFunctions;
}

void NameAndTypeResolver::warnVariablesNamedLikeInstructions(void)
{
auto declarations = nameFromCurrentScope("returndatasize");
for (Declaration const* const declaration : declarations)
{
solAssert(!!declaration, "");
m_errorReporter.warning(
declaration->location(),
"Variable is shadowed in an inline assembly by an insturction of the same name"
);
}
}

bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode)
{
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(&_node))
Expand Down
3 changes: 3 additions & 0 deletions libsolidity/analysis/NameAndTypeResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class NameAndTypeResolver: private boost::noncopyable
std::vector<Declaration const*> const& _declarations
);

/// Generate and store warnings about variables that are named like instructions.
void warnVariablesNamedLikeInstructions(void);

private:
/// Internal version of @a resolveNamesAndTypes (called from there) throws exceptions on fatal errors.
bool resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode = true);
Expand Down
2 changes: 2 additions & 0 deletions libsolidity/analysis/ReferencesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)

bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
{
m_resolver.warnVariablesNamedLikeInstructions();

// Errors created in this stage are completely ignored because we do not yet know
// the type and size of external identifiers, which would result in false errors.
// The only purpose of this step is to fill the inline assembly annotation with
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5744,7 +5744,7 @@ BOOST_AUTO_TEST_CASE(returndatacopy_as_variable)
char const* text = R"(
contract c { function f() { uint returndatasize; assembly { returndatasize }}}
)";
CHECK_WARNING_ALLOW_MULTI(text, "shadowed by an insturction of the same name");
CHECK_WARNING_ALLOW_MULTI(text, "Variable is shadowed in an inline assembly by an insturction of the same name");
}


Expand Down

0 comments on commit 6545b4f

Please sign in to comment.