Merge pull request #11315 from ethereum/minor-cf

ControlFlowAnalyzer: Use temporary reference for more readable code
This commit is contained in:
chriseth 2021-04-26 14:21:49 +02:00 committed by GitHub
commit ddc030267e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,18 +134,20 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
for (auto const* variableOccurrence: uninitializedAccessesOrdered) for (auto const* variableOccurrence: uninitializedAccessesOrdered)
{ {
VariableDeclaration const& varDecl = variableOccurrence->declaration();
SecondarySourceLocation ssl; SecondarySourceLocation ssl;
if (variableOccurrence->occurrence()) if (variableOccurrence->occurrence())
ssl.append("The variable was declared here.", variableOccurrence->declaration().location()); ssl.append("The variable was declared here.", varDecl.location());
bool isStorage = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::Storage); bool isStorage = varDecl.type()->dataStoredIn(DataLocation::Storage);
bool isCalldata = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::CallData); bool isCalldata = varDecl.type()->dataStoredIn(DataLocation::CallData);
if (isStorage || isCalldata) if (isStorage || isCalldata)
m_errorReporter.typeError( m_errorReporter.typeError(
3464_error, 3464_error,
variableOccurrence->occurrence() ? variableOccurrence->occurrence() ?
*variableOccurrence->occurrence() : *variableOccurrence->occurrence() :
variableOccurrence->declaration().location(), varDecl.location(),
ssl, ssl,
"This variable is of " + "This variable is of " +
string(isStorage ? "storage" : "calldata") + string(isStorage ? "storage" : "calldata") +
@ -153,10 +155,10 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod
(variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") + (variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") +
" without prior assignment, which would lead to undefined behaviour." " without prior assignment, which would lead to undefined behaviour."
); );
else if (!_emptyBody && variableOccurrence->declaration().name().empty()) else if (!_emptyBody && varDecl.name().empty())
m_errorReporter.warning( m_errorReporter.warning(
6321_error, 6321_error,
variableOccurrence->declaration().location(), varDecl.location(),
"Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable." "Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable."
); );
} }