Consider mappings return values in control flow analysis.

This commit is contained in:
Daniel Kirchner 2018-08-10 16:15:39 +02:00
parent a9f31da411
commit 4ae59acc09
6 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@ Breaking Changes:
* Commandline interface: Rename the ``--julia`` option to ``--yul``.
* Commandline interface: Require ``-`` if standard input is used as source.
* Compiler interface: Disallow remappings with empty prefix.
* Control Flow Analyzer: Consider mappings as well when checking for uninitialized return values.
* Control Flow Analyzer: Turn warning about returning uninitialized storage pointers into an error.
* General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code.
* General: Disallow declaring empty structs.

View File

@ -75,7 +75,10 @@ void ControlFlowAnalyzer::checkUnassignedStorageReturnValues(
{
auto& unassignedAtFunctionEntry = unassigned[_functionEntry];
for (auto const& returnParameter: _function.returnParameterList()->parameters())
if (returnParameter->type()->dataStoredIn(DataLocation::Storage))
if (
returnParameter->type()->dataStoredIn(DataLocation::Storage) ||
returnParameter->type()->category() == Type::Category::Mapping
)
unassignedAtFunctionEntry.insert(returnParameter.get());
}

View File

@ -0,0 +1,5 @@
contract C {
function f() internal pure returns (mapping(uint=>uint) storage r) { }
}
// ----
// TypeError: (53-82): This variable is of storage pointer type and might be returned without assignment and could be used uninitialized. Assign the variable (potentially from itself) to fix this error.

View File

@ -0,0 +1,5 @@
contract C {
mapping(uint=>uint) m;
function f() internal view returns (mapping(uint=>uint) storage r) { r = m; }
}
// ----

View File

@ -0,0 +1,5 @@
contract C {
function f() internal pure returns (mapping(uint=>uint) storage) {}
}
// ----
// TypeError: (53-72): This variable is of storage pointer type and might be returned without assignment and could be used uninitialized. Assign the variable (potentially from itself) to fix this error.

View File

@ -0,0 +1,5 @@
contract C {
mapping(uint=>uint) m;
function f() internal view returns (mapping(uint=>uint) storage) { return m; }
}
// ----