Skip to content

Commit 85448c8

Browse files
committed
Fix shadowing error for inline assembly.
1 parent ae519c1 commit 85448c8

File tree

20 files changed

+63
-37
lines changed

20 files changed

+63
-37
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bugfixes:
1717
* Code Generator: Fix internal compiler error when passing a 32-byte hex literal or a zero literal to ``bytes.concat()`` by disallowing such literals.
1818
* Commandline Interface: Fix crash when a directory path is passed to ``--standard-json``.
1919
* Commandline Interface: Read JSON from standard input when ``--standard-json`` gets ``-`` as a file name.
20+
* Inline Assembly: Consider functions, function parameters and return variables for shadowing checks.
2021
* Standard JSON: Include source location for errors in files with empty name.
2122
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
2223
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.

libsolidity/analysis/ReferencesResolver.cpp

Lines changed: 15 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,19 @@ 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+
ssl.append("The shadowed declaration is here:", decl->location());
375+
if (!ssl.infos.empty())
376+
m_errorReporter.declarationError(
377+
3859_error,
378+
_location,
379+
ssl,
380+
"This declaration shadows a declaration outside the inline assembly block."
381+
);
382+
}
388383
}

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/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 {

test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly/returning_function.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 returns (S storage c) {
4+
function g() internal pure returns (S storage c) {
55
// this should warn about unreachable code, but currently function flow is ignored
66
assembly {
77
function f() { return(0, 0) }

test/libsolidity/syntaxTests/controlFlow/storageReturn/assembly/reverting_function.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ contract C {
44
function f() internal pure returns (S storage c) {
55
// this could be allowed, but currently control flow for functions is not analysed
66
assembly {
7-
function f() { revert(0, 0) }
8-
f()
7+
function g() { revert(0, 0) }
8+
g()
99
}
1010
}
1111
}

test/libsolidity/syntaxTests/inlineAssembly/function_call_invalid_argument_count.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
contract C {
2-
function f() public pure {
2+
function g() public pure {
33
assembly {
44
function f(a) {}
55

0 commit comments

Comments
 (0)