diff --git a/Changelog.md b/Changelog.md index bff080bb6..025a6b453 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,8 @@ Language Features: Compiler Features: * SMTChecker: Support inline arrays. + * Control Flow Graph: Print warning for non-empty functions with unnamed return parameters that are not assigned a value in all code paths. + Bugfixes: * Code generator: Fix internal compiler error when referencing members via module name but not using the reference. diff --git a/docs/contracts/functions.rst b/docs/contracts/functions.rst index 204ea8f6d..2c79d3578 100644 --- a/docs/contracts/functions.rst +++ b/docs/contracts/functions.rst @@ -424,6 +424,8 @@ operations as long as there is enough gas passed on to it. // If someone sends Ether to that contract, the receive function in TestPayable will be called. require(address(test).send(2 ether)); // results in test.x becoming == 2 and test.y becoming 2 ether. + + return true; } } diff --git a/libsolidity/analysis/ControlFlowAnalyzer.cpp b/libsolidity/analysis/ControlFlowAnalyzer.cpp index 1ed66f72b..9346f5565 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.cpp +++ b/libsolidity/analysis/ControlFlowAnalyzer.cpp @@ -37,13 +37,13 @@ bool ControlFlowAnalyzer::visit(FunctionDefinition const& _function) if (_function.isImplemented()) { auto const& functionFlow = m_cfg.functionFlow(_function); - checkUninitializedAccess(functionFlow.entry, functionFlow.exit); + checkUninitializedAccess(functionFlow.entry, functionFlow.exit, _function.body().statements().empty()); checkUnreachable(functionFlow.entry, functionFlow.exit, functionFlow.revert, functionFlow.transactionReturn); } return false; } -void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit) const +void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody) const { struct NodeInfo { @@ -95,14 +95,10 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod case VariableOccurrence::Kind::Return: if (unassignedVariables.count(&variableOccurrence.declaration())) { - if ( - variableOccurrence.declaration().type()->dataStoredIn(DataLocation::Storage) || - variableOccurrence.declaration().type()->dataStoredIn(DataLocation::CallData) - ) - // Merely store the unassigned access. We do not generate an error right away, since this - // path might still always revert. It is only an error if this is propagated to the exit - // node of the function (i.e. there is a path with an uninitialized access). - nodeInfo.uninitializedVariableAccesses.insert(&variableOccurrence); + // Merely store the unassigned access. We do not generate an error right away, since this + // path might still always revert. It is only an error if this is propagated to the exit + // node of the function (i.e. there is a path with an uninitialized access). + nodeInfo.uninitializedVariableAccesses.insert(&variableOccurrence); } break; case VariableOccurrence::Kind::Declaration: @@ -140,18 +136,26 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod ssl.append("The variable was declared here.", variableOccurrence->declaration().location()); bool isStorage = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::Storage); - m_errorReporter.typeError( - 3464_error, - variableOccurrence->occurrence() ? - *variableOccurrence->occurrence() : + bool isCalldata = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::CallData); + if (isStorage || isCalldata) + m_errorReporter.typeError( + 3464_error, + variableOccurrence->occurrence() ? + *variableOccurrence->occurrence() : + variableOccurrence->declaration().location(), + ssl, + "This variable is of " + + string(isStorage ? "storage" : "calldata") + + " pointer type and can be " + + (variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") + + " without prior assignment, which would lead to undefined behaviour." + ); + else if (!_emptyBody && variableOccurrence->declaration().name().empty()) + m_errorReporter.warning( + 6321_error, variableOccurrence->declaration().location(), - ssl, - "This variable is of " + - string(isStorage ? "storage" : "calldata") + - " pointer type and can be " + - (variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") + - " without prior assignment, which would lead to undefined behaviour." - ); + "Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable." + ); } } } diff --git a/libsolidity/analysis/ControlFlowAnalyzer.h b/libsolidity/analysis/ControlFlowAnalyzer.h index c731cc31f..4e53fef78 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.h +++ b/libsolidity/analysis/ControlFlowAnalyzer.h @@ -36,7 +36,7 @@ public: private: /// Checks for uninitialized variable accesses in the control flow between @param _entry and @param _exit. - void checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit) const; + void checkUninitializedAccess(CFGNode const* _entry, CFGNode const* _exit, bool _emptyBody) const; /// Checks for unreachable code, i.e. code ending in @param _exit, @param _revert or @param _transactionReturn /// that can not be reached from @param _entry. void checkUnreachable(CFGNode const* _entry, CFGNode const* _exit, CFGNode const* _revert, CFGNode const* _transactionReturn) const; diff --git a/libsolidity/formal/PredicateInstance.cpp b/libsolidity/formal/PredicateInstance.cpp index 601891c5a..90fceab3c 100644 --- a/libsolidity/formal/PredicateInstance.cpp +++ b/libsolidity/formal/PredicateInstance.cpp @@ -64,7 +64,7 @@ smtutil::Expression constructor(Predicate const& _pred, ContractDefinition const return _pred(currentFunctionVariables(*constructor, &_contract, _context)); auto& state = _context.state(); - vector stateExprs{state.errorFlag().currentValue(), state.thisAddress(0), state.state()}; + vector stateExprs{state.errorFlag().currentValue(), state.thisAddress(0), state.state(0), state.state()}; return _pred(stateExprs + currentStateVariables(_contract, _context)); } diff --git a/libsolidity/formal/PredicateSort.cpp b/libsolidity/formal/PredicateSort.cpp index 5bcc5efcb..b9e1c1d40 100644 --- a/libsolidity/formal/PredicateSort.cpp +++ b/libsolidity/formal/PredicateSort.cpp @@ -60,7 +60,7 @@ SortPointer constructorSort(ContractDefinition const& _contract, SymbolicState& return functionSort(*constructor, &_contract, _state); return make_shared( - vector{_state.errorFlagSort(), _state.thisAddressSort(), _state.stateSort()} + stateSorts(_contract), + vector{_state.errorFlagSort(), _state.thisAddressSort(), _state.stateSort(), _state.stateSort()} + stateSorts(_contract), SortProvider::boolSort ); } diff --git a/libyul/optimiser/StackToMemoryMover.cpp b/libyul/optimiser/StackToMemoryMover.cpp index db9bbef21..ccac48296 100644 --- a/libyul/optimiser/StackToMemoryMover.cpp +++ b/libyul/optimiser/StackToMemoryMover.cpp @@ -49,6 +49,23 @@ vector generateMemoryStore( }}); return result; } + +FunctionCall generateMemoryLoad(Dialect const& _dialect, langutil::SourceLocation const& _loc, YulString _mpos) +{ + BuiltinFunction const* memoryLoadFunction = _dialect.memoryLoadFunction(_dialect.defaultType); + yulAssert(memoryLoadFunction, ""); + return FunctionCall{ + _loc, + Identifier{_loc, memoryLoadFunction->name}, { + Literal{ + _loc, + LiteralKind::Number, + _mpos, + {} + } + } + }; +} } void StackToMemoryMover::run( @@ -93,29 +110,34 @@ void StackToMemoryMover::operator()(FunctionDefinition& _functionDefinition) void StackToMemoryMover::operator()(Block& _block) { using OptionalStatements = std::optional>; - auto containsVariableNeedingEscalation = [&](auto const& _variables) { - return util::contains_if(_variables, [&](auto const& var) { + auto rewriteAssignmentOrVariableDeclaration = [&]( + auto& _stmt, + auto const& _variables + ) -> OptionalStatements { + using StatementType = decay_t; + if (_stmt.value) + visit(*_stmt.value); + bool leftHandSideNeedsMoving = util::contains_if(_variables, [&](auto const& var) { return m_memoryOffsetTracker(var.name); }); - }; - auto rewriteAssignmentOrVariableDeclaration = [&]( - langutil::SourceLocation const& _loc, - auto const& _variables, - std::unique_ptr _value - ) -> std::vector { + if (!leftHandSideNeedsMoving) + return {}; + + langutil::SourceLocation loc = _stmt.location; + if (_variables.size() == 1) { optional offset = m_memoryOffsetTracker(_variables.front().name); yulAssert(offset, ""); return generateMemoryStore( m_context.dialect, - _loc, + loc, *offset, - _value ? *std::move(_value) : Literal{_loc, LiteralKind::Number, "0"_yulstring, {}} + _stmt.value ? *std::move(_stmt.value) : Literal{loc, LiteralKind::Number, "0"_yulstring, {}} ); } - VariableDeclaration tempDecl{_loc, {}, std::move(_value)}; + VariableDeclaration tempDecl{loc, {}, std::move(_stmt.value)}; vector memoryAssignments; vector variableAssignments; for (auto& var: _variables) @@ -126,19 +148,14 @@ void StackToMemoryMover::operator()(Block& _block) if (optional offset = m_memoryOffsetTracker(var.name)) memoryAssignments += generateMemoryStore( m_context.dialect, - _loc, + loc, *offset, - Identifier{_loc, tempVarName} + Identifier{loc, tempVarName} ); - else if constexpr (std::is_same_v, Identifier>) - variableAssignments.emplace_back(Assignment{ - _loc, { Identifier{var.location, var.name} }, - make_unique(Identifier{_loc, tempVarName}) - }); else - variableAssignments.emplace_back(VariableDeclaration{ - _loc, {std::move(var)}, - make_unique(Identifier{_loc, tempVarName}) + variableAssignments.emplace_back(StatementType{ + loc, {move(var)}, + make_unique(Identifier{loc, tempVarName}) }); } std::vector result; @@ -147,65 +164,34 @@ void StackToMemoryMover::operator()(Block& _block) result += std::move(memoryAssignments); std::reverse(variableAssignments.begin(), variableAssignments.end()); result += std::move(variableAssignments); - return result; + return OptionalStatements{move(result)}; }; util::iterateReplacing( _block.statements, [&](Statement& _statement) { - auto defaultVisit = [&]() { ASTModifier::visit(_statement); return OptionalStatements{}; }; return std::visit(util::GenericVisitor{ [&](Assignment& _assignment) -> OptionalStatements { - if (!containsVariableNeedingEscalation(_assignment.variableNames)) - return defaultVisit(); - visit(*_assignment.value); - return {rewriteAssignmentOrVariableDeclaration( - _assignment.location, - _assignment.variableNames, - std::move(_assignment.value) - )}; + return rewriteAssignmentOrVariableDeclaration(_assignment, _assignment.variableNames); }, [&](VariableDeclaration& _varDecl) -> OptionalStatements { - if (!containsVariableNeedingEscalation(_varDecl.variables)) - return defaultVisit(); - if (_varDecl.value) - visit(*_varDecl.value); - return {rewriteAssignmentOrVariableDeclaration( - _varDecl.location, - _varDecl.variables, - std::move(_varDecl.value) - )}; + return rewriteAssignmentOrVariableDeclaration(_varDecl, _varDecl.variables); }, - [&](auto&) { return defaultVisit(); } + [&](auto& _stmt) -> OptionalStatements { (*this)(_stmt); return {}; } }, _statement); - }); + } + ); } void StackToMemoryMover::visit(Expression& _expression) { + ASTModifier::visit(_expression); if (Identifier* identifier = std::get_if(&_expression)) if (optional offset = m_memoryOffsetTracker(identifier->name)) - { - BuiltinFunction const* memoryLoadFunction = m_context.dialect.memoryLoadFunction(m_context.dialect.defaultType); - yulAssert(memoryLoadFunction, ""); - langutil::SourceLocation loc = identifier->location; - _expression = FunctionCall{ - loc, - Identifier{loc, memoryLoadFunction->name}, { - Literal{ - loc, - LiteralKind::Number, - *offset, - {} - } - } - }; - return; - } - ASTModifier::visit(_expression); + _expression = generateMemoryLoad(m_context.dialect, identifier->location, *offset); } optional StackToMemoryMover::VariableMemoryOffsetTracker::operator()(YulString _variable) const diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 3f311afe2..f07a16c83 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -126,7 +126,7 @@ void OptimiserSuite::run( { yulAssert(_meter, ""); ConstantOptimiser{*dialect, *_meter}(ast); - if (dialect->providesObjectAccess()) + if (dialect->providesObjectAccess() && _optimizeStackAllocation) StackLimitEvader::run(suite.m_context, _object, CompilabilityChecker{ _dialect, _object, diff --git a/test/cmdlineTests/optimizer_array_sload/input.sol b/test/cmdlineTests/optimizer_array_sload/input.sol index 1ad596601..3c8c3d212 100644 --- a/test/cmdlineTests/optimizer_array_sload/input.sol +++ b/test/cmdlineTests/optimizer_array_sload/input.sol @@ -4,8 +4,8 @@ pragma solidity >=0.0; contract Arraysum { uint256[] values; - function sumArray() public view returns(uint) { - uint sum = 0; + function sumArray() public view returns(uint sum) { + sum = 0; // The optimizer should read the length of the array only once, because // LoopInvariantCodeMotion can move the `sload` corresponding to the length outside of the // loop. diff --git a/test/cmdlineTests/optimizer_array_sload/output b/test/cmdlineTests/optimizer_array_sload/output index c7f8a9d7d..332df6778 100644 --- a/test/cmdlineTests/optimizer_array_sload/output +++ b/test/cmdlineTests/optimizer_array_sload/output @@ -43,7 +43,7 @@ object "Arraysum_33" { vloc_sum := add(vloc_sum, _3) } let memPos := allocateMemory(_1) - return(memPos, sub(abi_encode_uint(memPos, _1), memPos)) + return(memPos, sub(abi_encode_uint(memPos, vloc_sum), memPos)) } } revert(0, 0) diff --git a/test/libsolidity/smtCheckerTests/complex/warn_on_struct.sol b/test/libsolidity/smtCheckerTests/complex/warn_on_struct.sol index 0bbf08c56..6f73d845d 100644 --- a/test/libsolidity/smtCheckerTests/complex/warn_on_struct.sol +++ b/test/libsolidity/smtCheckerTests/complex/warn_on_struct.sol @@ -7,6 +7,7 @@ contract C { } } // ---- +// Warning 6321: (117-121): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 2072: (133-143): Unused local variable. // Warning 8364: (146-147): Assertion checker does not yet implement type type(struct C.A storage pointer) // Warning 4639: (146-163): Assertion checker does not yet implement this expression. diff --git a/test/libsolidity/smtCheckerTests/control_flow/require.sol b/test/libsolidity/smtCheckerTests/control_flow/require.sol index 1a63691b4..55ee33b33 100644 --- a/test/libsolidity/smtCheckerTests/control_flow/require.sol +++ b/test/libsolidity/smtCheckerTests/control_flow/require.sol @@ -30,4 +30,5 @@ contract C { } } // ---- +// Warning 6321: (429-442): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (448-465): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/control_flow/revert.sol b/test/libsolidity/smtCheckerTests/control_flow/revert.sol index 50e9e09a8..18650e5ff 100644 --- a/test/libsolidity/smtCheckerTests/control_flow/revert.sol +++ b/test/libsolidity/smtCheckerTests/control_flow/revert.sol @@ -32,4 +32,5 @@ contract C { // ---- // Warning 5740: (116-129): Unreachable code. // Warning 5740: (221-234): Unreachable code. +// Warning 6321: (408-421): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (427-444): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/control_flow/try_catch_1.sol b/test/libsolidity/smtCheckerTests/control_flow/try_catch_1.sol index 56d4dd804..78cb9264a 100644 --- a/test/libsolidity/smtCheckerTests/control_flow/try_catch_1.sol +++ b/test/libsolidity/smtCheckerTests/control_flow/try_catch_1.sol @@ -8,5 +8,6 @@ contract C { // ==== // EVMVersion: >=byzantium // ---- +// Warning 6321: (75-79): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 7645: (98-121): Assertion checker does not support try/catch clauses. // Warning 7645: (124-159): Assertion checker does not support try/catch clauses. diff --git a/test/libsolidity/smtCheckerTests/functions/function_external_call_should_not_inline_1.sol b/test/libsolidity/smtCheckerTests/functions/function_external_call_should_not_inline_1.sol index 8b8ceed1a..2bacad7e2 100644 --- a/test/libsolidity/smtCheckerTests/functions/function_external_call_should_not_inline_1.sol +++ b/test/libsolidity/smtCheckerTests/functions/function_external_call_should_not_inline_1.sol @@ -13,3 +13,4 @@ contract C { } } // ---- +// Warning 6321: (85-89): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/functions/internal_call_state_var_init_2.sol b/test/libsolidity/smtCheckerTests/functions/internal_call_state_var_init_2.sol index ef7cb6647..5c94cd9ed 100644 --- a/test/libsolidity/smtCheckerTests/functions/internal_call_state_var_init_2.sol +++ b/test/libsolidity/smtCheckerTests/functions/internal_call_state_var_init_2.sol @@ -7,3 +7,4 @@ contract c { bool b = (f() > 0) || (f() > 0); } // ---- +// Warning 6321: (86-90): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/functions/recursive_multi_return.sol b/test/libsolidity/smtCheckerTests/functions/recursive_multi_return.sol index 0c2a781fc..d0d52c937 100644 --- a/test/libsolidity/smtCheckerTests/functions/recursive_multi_return.sol +++ b/test/libsolidity/smtCheckerTests/functions/recursive_multi_return.sol @@ -9,3 +9,5 @@ contract C { } // // ---- +// Warning 6321: (81-85): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (87-91): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/functions/recursive_multi_return_2.sol b/test/libsolidity/smtCheckerTests/functions/recursive_multi_return_2.sol index cb4773841..b01d8cb05 100644 --- a/test/libsolidity/smtCheckerTests/functions/recursive_multi_return_2.sol +++ b/test/libsolidity/smtCheckerTests/functions/recursive_multi_return_2.sol @@ -23,5 +23,18 @@ a; } } // ---- +// Warning 6321: (163-167): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (171-175): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (179-183): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (187-191): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (195-199): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (203-207): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (211-215): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (219-223): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (227-231): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (235-239): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (241-244): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (246-250): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (252-259): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6133: (72-90): Statement has no effect. // Warning 6133: (96-107): Statement has no effect. diff --git a/test/libsolidity/smtCheckerTests/math/addmod_mulmod_zero.sol b/test/libsolidity/smtCheckerTests/math/addmod_mulmod_zero.sol index 1fa190e65..7c8b7ac10 100644 --- a/test/libsolidity/smtCheckerTests/math/addmod_mulmod_zero.sol +++ b/test/libsolidity/smtCheckerTests/math/addmod_mulmod_zero.sol @@ -21,6 +21,7 @@ contract C { } } // ---- +// Warning 6321: (253-260): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 1218: (94-109): CHC: Error trying to invoke SMT solver. // Warning 1218: (113-126): CHC: Error trying to invoke SMT solver. // Warning 1218: (180-195): CHC: Error trying to invoke SMT solver. diff --git a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_and_fixed_bytes.sol b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_and_fixed_bytes.sol index b1db36acd..ec505bda9 100644 --- a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_and_fixed_bytes.sol +++ b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_and_fixed_bytes.sol @@ -11,4 +11,5 @@ contract C { } } // ---- +// Warning 6321: (83-87): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (203-217): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_or_fixed_bytes.sol b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_or_fixed_bytes.sol index 613ac8952..b433ba613 100644 --- a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_or_fixed_bytes.sol +++ b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_or_fixed_bytes.sol @@ -11,4 +11,5 @@ contract C { } } // ---- +// Warning 6321: (83-87): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (203-217): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_xor_fixed_bytes.sol b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_xor_fixed_bytes.sol index f1d57b68e..e30e1e51e 100644 --- a/test/libsolidity/smtCheckerTests/operators/compound_bitwise_xor_fixed_bytes.sol +++ b/test/libsolidity/smtCheckerTests/operators/compound_bitwise_xor_fixed_bytes.sol @@ -11,4 +11,5 @@ contract C { } } // ---- +// Warning 6321: (83-87): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (204-221): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/overflow/overflow_sum_signed.sol b/test/libsolidity/smtCheckerTests/overflow/overflow_sum_signed.sol index 473c12447..8b4e2f380 100644 --- a/test/libsolidity/smtCheckerTests/overflow/overflow_sum_signed.sol +++ b/test/libsolidity/smtCheckerTests/overflow/overflow_sum_signed.sol @@ -14,6 +14,7 @@ contract C } } // ---- +// Warning 6321: (87-91): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 4984: (117-122): CHC: Overflow (resulting value larger than 127) happens here. // Warning 4984: (151-158): CHC: Overflow (resulting value larger than 127) happens here. // Warning 3944: (197-205): CHC: Underflow (resulting value less than -128) happens here. diff --git a/test/libsolidity/smtCheckerTests/special/event.sol b/test/libsolidity/smtCheckerTests/special/event.sol index b804370c9..6fb17c22f 100644 --- a/test/libsolidity/smtCheckerTests/special/event.sol +++ b/test/libsolidity/smtCheckerTests/special/event.sol @@ -25,4 +25,6 @@ contract C { } } // ---- +// Warning 6321: (280-284): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (430-434): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (440-449): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/special/log.sol b/test/libsolidity/smtCheckerTests/special/log.sol index 86a36a3c9..4dcdfc868 100644 --- a/test/libsolidity/smtCheckerTests/special/log.sol +++ b/test/libsolidity/smtCheckerTests/special/log.sol @@ -36,4 +36,5 @@ contract C { } } // ---- +// Warning 6321: (655-662): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (668-677): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/types/no_effect_statements.sol b/test/libsolidity/smtCheckerTests/types/no_effect_statements.sol index d97d33cbe..742a2fe67 100644 --- a/test/libsolidity/smtCheckerTests/types/no_effect_statements.sol +++ b/test/libsolidity/smtCheckerTests/types/no_effect_statements.sol @@ -10,6 +10,7 @@ contract test { } } // ---- +// Warning 6321: (115-119): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6133: (125-126): Statement has no effect. // Warning 6133: (130-136): Statement has no effect. // Warning 6133: (140-144): Statement has no effect. diff --git a/test/libsolidity/smtCheckerTests/types/rational_large_1.sol b/test/libsolidity/smtCheckerTests/types/rational_large_1.sol index a6b74520b..242695bc2 100644 --- a/test/libsolidity/smtCheckerTests/types/rational_large_1.sol +++ b/test/libsolidity/smtCheckerTests/types/rational_large_1.sol @@ -7,4 +7,5 @@ contract c { } } // ---- +// Warning 6321: (80-84): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (128-142): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_1.sol b/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_1.sol index 7bbaaec04..61097f834 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_1.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_1.sol @@ -8,4 +8,5 @@ contract C { } } // ---- +// Warning 6321: (79-82): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (157-171): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_2.sol b/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_2.sol index 0670a558f..f2798ed46 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_2.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_different_count_assignment_2.sol @@ -8,4 +8,5 @@ contract C { } } // ---- +// Warning 6321: (79-82): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6328: (159-173): CHC: Assertion violation happens here. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_1.sol b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_1.sol index e238bd62a..1a0f36319 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_1.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_1.sol @@ -5,3 +5,5 @@ contract C { ((, a)) = (1, 2); } } +// ---- +// Warning 6321: (80-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_2.sol b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_2.sol index 30cd2608f..1807864e6 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_2.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_2.sol @@ -5,3 +5,5 @@ contract C { (((, a),)) = ((1, 2), 3); } } +// ---- +// Warning 6321: (80-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_3.sol b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_3.sol index 84ceb4e36..03ce76ea6 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_3.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_3.sol @@ -5,3 +5,5 @@ contract C { (((((((, a),)))))) = ((1, 2), 3); } } +// ---- +// Warning 6321: (80-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_4.sol b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_4.sol index 8243e938e..d97216f13 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_4.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_4.sol @@ -5,3 +5,5 @@ contract C { ((((((, a)))),)) = ((1, 2), 3); } } +// ---- +// Warning 6321: (80-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_5.sol b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_5.sol index 2288a94ca..b6ac3a5c1 100644 --- a/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_5.sol +++ b/test/libsolidity/smtCheckerTests/types/tuple_extra_parens_5.sol @@ -5,3 +5,5 @@ contract C { ((((((((((((, a))))))),))))) = ((1, 2), 3); } } +// ---- +// Warning 6321: (80-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/abiEncoder/v2_accessing_returned_dynamic_array_with_returndata_support.sol b/test/libsolidity/syntaxTests/abiEncoder/v2_accessing_returned_dynamic_array_with_returndata_support.sol index 27f55764e..bc3b4ce36 100644 --- a/test/libsolidity/syntaxTests/abiEncoder/v2_accessing_returned_dynamic_array_with_returndata_support.sol +++ b/test/libsolidity/syntaxTests/abiEncoder/v2_accessing_returned_dynamic_array_with_returndata_support.sol @@ -10,4 +10,5 @@ contract C { // ==== // EVMVersion: >=byzantium // ---- +// Warning 6321: (150-154): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 2072: (166-183): Unused local variable. diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol index ec83c596e..5a4173ab6 100644 --- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol +++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/default_location.sol @@ -17,3 +17,4 @@ contract C { } } // ---- +// Warning 6321: (399-407): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol b/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol index ea019198d..6972c7a27 100644 --- a/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol +++ b/test/libsolidity/syntaxTests/dataLocations/function_return_parameters_with_data_location_fine.sol @@ -4,3 +4,6 @@ contract C { function h() public pure returns(uint[] memory) {} function i() external pure returns(uint[] memory) {} } +// ---- +// Warning 6321: (51-64): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (134-147): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/freeFunctions/qualified_struct_access.sol b/test/libsolidity/syntaxTests/freeFunctions/qualified_struct_access.sol index ab027e21d..2d9a3011b 100644 --- a/test/libsolidity/syntaxTests/freeFunctions/qualified_struct_access.sol +++ b/test/libsolidity/syntaxTests/freeFunctions/qualified_struct_access.sol @@ -4,4 +4,5 @@ contract C { struct S { uint x; } } // ---- +// Warning 6321: (22-26): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // TypeError 3464: (45-46): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour. diff --git a/test/libsolidity/syntaxTests/metaTypes/typeOfContract.sol b/test/libsolidity/syntaxTests/metaTypes/typeOfContract.sol index bd434fc26..53b2d819e 100644 --- a/test/libsolidity/syntaxTests/metaTypes/typeOfContract.sol +++ b/test/libsolidity/syntaxTests/metaTypes/typeOfContract.sol @@ -4,4 +4,5 @@ contract Test { } } // ---- +// Warning 6321: (54-66): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6133: (78-88): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol index 7db98577e..28c4cec5c 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiSingleVariableDeclaration.sol @@ -4,3 +4,5 @@ contract C { a; } } +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol index ba6e99163..b1ec065ac 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol @@ -9,3 +9,7 @@ contract C { function g() internal pure returns (uint, uint, uint, D.S[20] storage x, uint) { x = x; } } // ---- +// Warning 6321: (176-180): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (182-186): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (188-192): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (213-217): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol index a2fcce182..e6a0dbe80 100644 --- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol +++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol @@ -10,3 +10,8 @@ contract C { function h() internal pure returns (bytes memory, string storage s) { s = s; } } // ---- +// Warning 6321: (51-55): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (57-61): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (63-67): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (69-73): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (250-262): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol index fd9ab7ed3..c6a9d30ca 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/018_forward_function_reference.sol @@ -8,3 +8,5 @@ contract Second { if (First(2).fun() == true) return 1; } } +// ---- +// Warning 6321: (183-187): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/no_effect_statements.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/no_effect_statements.sol index 68b588ad8..049834de9 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/no_effect_statements.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/no_effect_statements.sol @@ -9,6 +9,7 @@ contract test { } } // ---- +// Warning 6321: (83-87): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 6133: (93-94): Statement has no effect. // Warning 6133: (98-104): Statement has no effect. // Warning 6133: (108-112): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/parsing/address_payable_function_type.sol b/test/libsolidity/syntaxTests/parsing/address_payable_function_type.sol index 234b528a8..2a0a04659 100644 --- a/test/libsolidity/syntaxTests/parsing/address_payable_function_type.sol +++ b/test/libsolidity/syntaxTests/parsing/address_payable_function_type.sol @@ -4,3 +4,5 @@ contract C { function (address payable) payable external returns (address payable) h; h; } } +// ---- +// Warning 6321: (197-267): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/parsing/if_statement.sol b/test/libsolidity/syntaxTests/parsing/if_statement.sol index b64920310..580a0f557 100644 --- a/test/libsolidity/syntaxTests/parsing/if_statement.sol +++ b/test/libsolidity/syntaxTests/parsing/if_statement.sol @@ -4,5 +4,6 @@ contract test { } } // ---- +// Warning 6321: (60-64): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 2072: (109-115): Unused local variable. // Warning 2018: (20-128): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/tryCatch/almost_call_options.sol b/test/libsolidity/syntaxTests/tryCatch/almost_call_options.sol index 91da9e312..49ee9ad5e 100644 --- a/test/libsolidity/syntaxTests/tryCatch/almost_call_options.sol +++ b/test/libsolidity/syntaxTests/tryCatch/almost_call_options.sol @@ -11,4 +11,6 @@ contract C { // ==== // EVMVersion: >=byzantium // ---- +// Warning 6321: (73-77): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (79-83): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. // Warning 2072: (122-134): Unused local variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/catch_error.sol b/test/libsolidity/syntaxTests/tryCatch/catch_error.sol index 34fc2431e..ccdfac28b 100644 --- a/test/libsolidity/syntaxTests/tryCatch/catch_error.sol +++ b/test/libsolidity/syntaxTests/tryCatch/catch_error.sol @@ -8,4 +8,7 @@ contract C { } } // ==== -// EVMVersion: >=byzantium \ No newline at end of file +// EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol b/test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol index 1a4a1273a..590c6cbba 100644 --- a/test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol +++ b/test/libsolidity/syntaxTests/tryCatch/catch_error_named.sol @@ -8,4 +8,7 @@ contract C { } } // ==== -// EVMVersion: >=byzantium \ No newline at end of file +// EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol b/test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol index 58948e211..68e7cc32f 100644 --- a/test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol +++ b/test/libsolidity/syntaxTests/tryCatch/catch_low_level.sol @@ -8,4 +8,7 @@ contract C { } } // ==== -// EVMVersion: >=byzantium \ No newline at end of file +// EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/no_returns.sol b/test/libsolidity/syntaxTests/tryCatch/no_returns.sol index bfda49ab9..a32853053 100644 --- a/test/libsolidity/syntaxTests/tryCatch/no_returns.sol +++ b/test/libsolidity/syntaxTests/tryCatch/no_returns.sol @@ -6,4 +6,7 @@ contract C { } } -} \ No newline at end of file +} +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/returns.sol b/test/libsolidity/syntaxTests/tryCatch/returns.sol index 507a83905..335270b0b 100644 --- a/test/libsolidity/syntaxTests/tryCatch/returns.sol +++ b/test/libsolidity/syntaxTests/tryCatch/returns.sol @@ -8,3 +8,6 @@ contract C { } } } +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/returns_memory.sol b/test/libsolidity/syntaxTests/tryCatch/returns_memory.sol index f71a4af25..d575e455e 100644 --- a/test/libsolidity/syntaxTests/tryCatch/returns_memory.sol +++ b/test/libsolidity/syntaxTests/tryCatch/returns_memory.sol @@ -9,3 +9,6 @@ contract C { } // ==== // EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-59): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (61-65): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/returns_memory_anonymous.sol b/test/libsolidity/syntaxTests/tryCatch/returns_memory_anonymous.sol index 9eb8f86c4..4647e762e 100644 --- a/test/libsolidity/syntaxTests/tryCatch/returns_memory_anonymous.sol +++ b/test/libsolidity/syntaxTests/tryCatch/returns_memory_anonymous.sol @@ -8,4 +8,7 @@ contract C { } } // ==== -// EVMVersion: >=byzantium \ No newline at end of file +// EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-59): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (61-65): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol b/test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol index fe2beb426..7ca4376fe 100644 --- a/test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol +++ b/test/libsolidity/syntaxTests/tryCatch/two_catch_clauses.sol @@ -11,4 +11,7 @@ contract C { } } // ==== -// EVMVersion: >=byzantium \ No newline at end of file +// EVMVersion: >=byzantium +// ---- +// Warning 6321: (46-50): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (52-56): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/tupleAssignments/large_component_count.sol b/test/libsolidity/syntaxTests/tupleAssignments/large_component_count.sol index f14641cb9..e941a0eb1 100644 --- a/test/libsolidity/syntaxTests/tupleAssignments/large_component_count.sol +++ b/test/libsolidity/syntaxTests/tupleAssignments/large_component_count.sol @@ -21,3 +21,6 @@ contract C { } } // ---- +// Warning 6321: (194-198): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (200-204): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. +// Warning 6321: (206-213): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/types/function_types/selector/local_variable_selector_not_pure.sol b/test/libsolidity/syntaxTests/types/function_types/selector/local_variable_selector_not_pure.sol index 481683af3..aeb2f6cd8 100644 --- a/test/libsolidity/syntaxTests/types/function_types/selector/local_variable_selector_not_pure.sol +++ b/test/libsolidity/syntaxTests/types/function_types/selector/local_variable_selector_not_pure.sol @@ -6,3 +6,5 @@ contract C { g.selector; } } +// ---- +// Warning 6321: (51-57): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol index 5aa21ce1a..740f83cc8 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/call_internal_functions_success.sol @@ -4,3 +4,5 @@ contract C { function h() public { h(); g(); f(); } function i() payable public { i(); h(); g(); f(); } } +// ---- +// Warning 6321: (89-93): Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable. diff --git a/test/libsolidity/util/BytesUtils.cpp b/test/libsolidity/util/BytesUtils.cpp index d095a0a76..e3a6fd4ed 100644 --- a/test/libsolidity/util/BytesUtils.cpp +++ b/test/libsolidity/util/BytesUtils.cpp @@ -218,7 +218,7 @@ string BytesUtils::formatRawBytes( auto it = _bytes.begin(); if (_bytes.size() != ContractABIUtils::encodingSize(_parameters)) - parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32)); + parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32); else parameters = _parameters; @@ -320,7 +320,7 @@ string BytesUtils::formatBytesRange( auto it = _bytes.begin(); if (_bytes.size() != ContractABIUtils::encodingSize(_parameters)) - parameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32)); + parameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32); else parameters = _parameters; diff --git a/test/libsolidity/util/ContractABIUtils.cpp b/test/libsolidity/util/ContractABIUtils.cpp index e3ab01128..520569907 100644 --- a/test/libsolidity/util/ContractABIUtils.cpp +++ b/test/libsolidity/util/ContractABIUtils.cpp @@ -20,6 +20,9 @@ #include +#include +#include + #include #include @@ -314,23 +317,34 @@ solidity::frontend::test::ParameterList ContractABIUtils::defaultParameters(size return parameters; } -solidity::frontend::test::ParameterList ContractABIUtils::failureParameters(bytes const _bytes) +solidity::frontend::test::ParameterList ContractABIUtils::failureParameters(bytes const& _bytes) { - ParameterList parameters; - - parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 4}, FormatInfo{}}); - if (_bytes.size() > 4) + if (_bytes.empty()) + return {}; + else if (_bytes.size() < 4) + return {Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, _bytes.size()}, FormatInfo{}}}; + else { - parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::Hex}, FormatInfo{}}); - parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::UnsignedDec}, FormatInfo{}}); + ParameterList parameters; + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 4}, FormatInfo{}}); + + uint64_t selector = fromBigEndian(bytes{_bytes.begin(), _bytes.begin() + 4}); + if (selector == selectorFromSignature32("Panic(uint256)")) + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::Hex}, FormatInfo{}}); + else if (selector == selectorFromSignature32("Error(string)")) + { + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::Hex}, FormatInfo{}}); + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::UnsignedDec}, FormatInfo{}}); + /// If _bytes contains at least a 1 byte message (function selector + tail pointer + message length + message) + /// append an additional string parameter to represent that message. + if (_bytes.size() > 68) + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::String}, FormatInfo{}}); + } + else + for (size_t i = 4; i < _bytes.size(); i += 32) + parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::HexString, ABIType::AlignNone, 32}, FormatInfo{}}); + return parameters; } - - /// If _bytes contains at least a 1 byte message (function selector + tail pointer + message length + message) - /// append an additional string parameter to represent that message. - if (_bytes.size() > 68) - parameters.push_back(Parameter{bytes(), "", ABIType{ABIType::String}, FormatInfo{}}); - - return parameters; } size_t ContractABIUtils::encodingSize( diff --git a/test/libsolidity/util/ContractABIUtils.h b/test/libsolidity/util/ContractABIUtils.h index 0e56c98e5..209eca423 100644 --- a/test/libsolidity/util/ContractABIUtils.h +++ b/test/libsolidity/util/ContractABIUtils.h @@ -65,7 +65,7 @@ public: /// returned values in case of a failure. Creates an additional parameter /// for the error message if _bytes is larger than 68 bytes /// (function_selector + tail_ptr + message_length). - static ParameterList failureParameters(bytes const _bytes); + static ParameterList failureParameters(bytes const& _bytes); /// Returns _count parameters with their type set to ABIType::UnsignedDec /// and their size set to 32 bytes. diff --git a/test/libsolidity/util/TestFunctionCall.cpp b/test/libsolidity/util/TestFunctionCall.cpp index b614d17b9..e258a4976 100644 --- a/test/libsolidity/util/TestFunctionCall.cpp +++ b/test/libsolidity/util/TestFunctionCall.cpp @@ -159,7 +159,7 @@ string TestFunctionCall::format( BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) : BytesUtils::formatRawBytes( output, - ContractABIUtils::defaultParameters(ceil(output.size() / 32)), + ContractABIUtils::defaultParameters((output.size() + 31) / 32), _linePrefix ); @@ -248,7 +248,7 @@ string TestFunctionCall::formatBytesParameters( } else { - ParameterList defaultParameters = ContractABIUtils::defaultParameters(ceil(_bytes.size() / 32)); + ParameterList defaultParameters = ContractABIUtils::defaultParameters((_bytes.size() + 31) / 32); ContractABIUtils::overwriteParameters(_errorReporter, defaultParameters, _parameters); os << BytesUtils::formatBytesRange(_bytes, defaultParameters, _highlight);