Skip to content

Commit aeb2438

Browse files
committed
Fix shadowing error for inline assembly.
1 parent 838514a commit aeb2438

25 files changed

+67
-56
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Breaking changes:
44
* `error` is now a keyword that can only be used for defining errors.
5+
* Inline Assembly: Consider functions, function parameters and return variables for shadowing checks.
56

67

78
### 0.8.8 (unreleased)

libsolidity/analysis/ReferencesResolver.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,8 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
274274
void ReferencesResolver::operator()(yul::VariableDeclaration const& _varDecl)
275275
{
276276
for (auto const& identifier: _varDecl.variables)
277-
{
278277
validateYulIdentifierName(identifier.name, identifier.debugData->location);
279278

280-
281-
if (
282-
auto declarations = m_resolver.nameFromCurrentScope(identifier.name.str());
283-
!declarations.empty()
284-
)
285-
{
286-
SecondarySourceLocation ssl;
287-
for (auto const* decl: declarations)
288-
ssl.append("The shadowed declaration is here:", decl->location());
289-
if (!ssl.infos.empty())
290-
m_errorReporter.declarationError(
291-
3859_error,
292-
identifier.debugData->location,
293-
ssl,
294-
"This declaration shadows a declaration outside the inline assembly block."
295-
);
296-
}
297-
}
298-
299279
if (_varDecl.value)
300280
visit(*_varDecl.value);
301281
}
@@ -385,4 +365,20 @@ void ReferencesResolver::validateYulIdentifierName(yul::YulString _name, SourceL
385365
_location,
386366
"The identifier name \"" + _name.str() + "\" is reserved."
387367
);
368+
369+
auto declarations = m_resolver.nameFromCurrentScope(_name.str());
370+
if (!declarations.empty())
371+
{
372+
SecondarySourceLocation ssl;
373+
for (auto const* decl: declarations)
374+
if (decl->location().hasText())
375+
ssl.append("The shadowed declaration is here:", decl->location());
376+
if (!ssl.infos.empty())
377+
m_errorReporter.declarationError(
378+
3859_error,
379+
_location,
380+
ssl,
381+
"This declaration shadows a declaration outside the inline assembly block."
382+
);
383+
}
388384
}

libyul/AsmAnalysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
323323
returnTypes = &_fun.returns;
324324
}
325325
}))
326-
else
327326
{
328327
if (!validateInstructions(_funCall))
329328
m_errorReporter.declarationError(

test/libsolidity/semanticTests/inlineAssembly/external_identifier_access_shadowing.sol

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/libsolidity/semanticTests/inlineAssembly/inline_assembly_storage_access_inside_function.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ contract C {
77
uint256 off1;
88
uint256 off2;
99
assembly {
10-
function f() -> o1 {
10+
function g() -> o1 {
1111
sstore(z.slot, 7)
1212
o1 := y.offset
1313
}
14-
off2 := f()
14+
off2 := g()
1515
}
1616
assert(off2 == 2);
1717
return true;

test/libsolidity/semanticTests/inlineAssembly/leave.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() public pure returns (uint w) {
2+
function g() public pure returns (uint w) {
33
assembly {
44
function f() -> t {
55
t := 2
@@ -14,4 +14,4 @@ contract C {
1414
// compileToEwasm: also
1515
// compileViaYul: also
1616
// ----
17-
// f() -> 2
17+
// g() -> 2

test/libsolidity/smtCheckerTests/inline_assembly/assembly_local_storage_access_inside_function.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
contract C {
22
uint256 public z;
33

4-
function f() public {
4+
function g() public {
55
z = 42;
66
uint i = 32;
77
assembly {

test/libsolidity/syntaxTests/controlFlow/leave_inside_function.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
contract C {
22
function f() public pure {
33
assembly {
4-
function f() {
4+
function g() {
55
// Make sure this doesn't trigger the unimplemented assertion in the control flow builder.
66
leave
77
}

test/libsolidity/syntaxTests/controlFlow/localStorageVariables/assembly/returning_function_declaration.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
contract C {
22
struct S { bool f; }
33
S s;
4-
function f() internal pure {
4+
function g() internal pure {
55
S storage c;
66
// this should warn about unreachable code, but currently function flow is ignored
77
assembly {

test/libsolidity/syntaxTests/controlFlow/localStorageVariables/assembly/reverting_function_declaration.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
contract C {
22
struct S { bool f; }
33
S s;
4-
function f() internal pure {
4+
function g() internal pure {
55
S storage c;
66
// this could be allowed, but currently control flow for functions is not analysed
77
assembly {

0 commit comments

Comments
 (0)