diff --git a/Changelog.md b/Changelog.md index c5625d9db..c8f0789f8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ Compiler Features: Bugfixes: + * Commandline Interface: Fix internal error when using ``--stop-after parsing`` and requesting some of the outputs that require full analysis or compilation. * Commandline Interface: It is no longer possible to specify both ``--optimize-yul`` and ``--no-optimize-yul`` at the same time. * SMTChecker: Fix encoding of side-effects inside ``if`` and ``ternary conditional``statements in the BMC engine. * SMTChecker: Fix false negative when a verification target can be violated only by trusted external call from another public function. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index ae6888dfd..7a28900b3 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -914,9 +914,9 @@ void CommandLineInterface::handleCombinedJSON() { output[g_strSources][sourceCode.first] = Json::Value(Json::objectValue); output[g_strSources][sourceCode.first]["AST"] = ASTJsonExporter( - m_compiler->state(), - m_compiler->sourceIndices() - ).toJson(m_compiler->ast(sourceCode.first)); + m_compiler->state(), + m_compiler->sourceIndices() + ).toJson(m_compiler->ast(sourceCode.first)); output[g_strSources][sourceCode.first]["id"] = m_compiler->sourceIndices().at(sourceCode.first); } } diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 9cc93d78d..dda7a6ba2 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -997,21 +997,11 @@ void CommandLineParser::processArgs() return; checkMutuallyExclusive({g_strColor, g_strNoColor}); + checkMutuallyExclusive({g_strStopAfter, g_strGas}); - array const conflictingWithStopAfter{ - CompilerOutputs::componentName(&CompilerOutputs::binary), - CompilerOutputs::componentName(&CompilerOutputs::ir), - CompilerOutputs::componentName(&CompilerOutputs::irAstJson), - CompilerOutputs::componentName(&CompilerOutputs::irOptimized), - CompilerOutputs::componentName(&CompilerOutputs::irOptimizedAstJson), - g_strGas, - CompilerOutputs::componentName(&CompilerOutputs::asm_), - CompilerOutputs::componentName(&CompilerOutputs::asmJson), - CompilerOutputs::componentName(&CompilerOutputs::opcodes), - }; - - for (auto& option: conflictingWithStopAfter) - checkMutuallyExclusive({g_strStopAfter, option}); + for (string const& option: CompilerOutputs::componentMap() | ranges::views::keys) + if (option != CompilerOutputs::componentName(&CompilerOutputs::astCompactJson)) + checkMutuallyExclusive({g_strStopAfter, option}); if ( m_options.input.mode != InputMode::Compiler && diff --git a/test/cmdlineTests/standard_stop_after_parsing_ast_requested/args b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/args new file mode 100644 index 000000000..18532c5a6 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/args @@ -0,0 +1 @@ +--allow-paths . diff --git a/test/cmdlineTests/standard_stop_after_parsing_ast_requested/in.sol b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/in.sol new file mode 100644 index 000000000..e78a24ff7 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/in.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity *; + +import "A"; + +contract C {} diff --git a/test/cmdlineTests/standard_stop_after_parsing_ast_requested/input.json b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/input.json new file mode 100644 index 000000000..34f157495 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/input.json @@ -0,0 +1,12 @@ +{ + "language": "Solidity", + "sources": { + "C": {"urls": ["standard_stop_after_parsing_ast_requested/in.sol"]} + }, + "settings": { + "stopAfter": "parsing", + "outputSelection": { + "*": {"": ["ast"]} + } + } +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_ast_requested/output.json b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/output.json new file mode 100644 index 000000000..6907d4780 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_ast_requested/output.json @@ -0,0 +1,54 @@ +{ + "sources": + { + "C": + { + "ast": + { + "absolutePath": "C", + "id": 4, + "license": "GPL-3.0", + "nodeType": "SourceUnit", + "nodes": + [ + { + "id": 1, + "literals": + [ + "solidity", + "*" + ], + "nodeType": "PragmaDirective", + "src": "36:18:0" + }, + { + "absolutePath": "A", + "file": "A", + "id": 2, + "nameLocation": "-1:-1:-1", + "nodeType": "ImportDirective", + "src": "56:11:0", + "symbolAliases": [], + "unitAlias": "" + }, + { + "abstract": false, + "baseContracts": [], + "contractDependencies": [], + "contractKind": "contract", + "id": 3, + "name": "C", + "nameLocation": "78:1:0", + "nodeType": "ContractDefinition", + "nodes": [], + "src": "69:13:0", + "usedErrors": [], + "usedEvents": [] + } + ], + "src": "36:47:0" + }, + "id": 0 + } + } +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/args b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/args new file mode 100644 index 000000000..18532c5a6 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/args @@ -0,0 +1 @@ +--allow-paths . diff --git a/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/in.sol b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/in.sol new file mode 100644 index 000000000..e78a24ff7 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/in.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity *; + +import "A"; + +contract C {} diff --git a/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/input.json b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/input.json new file mode 100644 index 000000000..7ef3d37fd --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/input.json @@ -0,0 +1,12 @@ +{ + "language": "Solidity", + "sources": { + "C": {"urls": ["standard_stop_after_parsing_bytecode_requested/in.sol"]} + }, + "settings": { + "stopAfter": "parsing", + "outputSelection": { + "*": {"*": ["evm.bytecode.object"]} + } + } +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/output.json b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/output.json new file mode 100644 index 000000000..371953096 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_bytecode_requested/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "Requested output selection conflicts with \"settings.stopAfter\".", + "message": "Requested output selection conflicts with \"settings.stopAfter\".", + "severity": "error", + "type": "JSONError" + } + ] +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/args b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/args new file mode 100644 index 000000000..18532c5a6 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/args @@ -0,0 +1 @@ +--allow-paths . diff --git a/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/in.sol b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/in.sol new file mode 100644 index 000000000..978517b3c --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/in.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity *; + +import "A"; + +contract C { + function f() public {} +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/input.json b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/input.json new file mode 100644 index 000000000..ac4d623c7 --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/input.json @@ -0,0 +1,19 @@ +{ + "language": "Solidity", + "sources": { + "C": {"urls": ["standard_stop_after_parsing_non_binary_output_requested/in.sol"]} + }, + "settings": { + "stopAfter": "parsing", + "outputSelection": { + "*": {"*": [ + "abi", + "devdoc", + "userdoc", + "metadata", + "storageLayout", + "evm.methodIdentifiers" + ]} + } + } +} diff --git a/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/output.json b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/output.json new file mode 100644 index 000000000..5b64763be --- /dev/null +++ b/test/cmdlineTests/standard_stop_after_parsing_non_binary_output_requested/output.json @@ -0,0 +1,9 @@ +{ + "sources": + { + "C": + { + "id": 0 + } + } +} diff --git a/test/cmdlineTests/stop_after_parsing_abi/args b/test/cmdlineTests/stop_after_parsing_abi/args new file mode 100644 index 000000000..9ec9f63e4 --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_abi/args @@ -0,0 +1 @@ +--pretty-json --json-indent 4 --stop-after parsing --abi diff --git a/test/cmdlineTests/stop_after_parsing_abi/err b/test/cmdlineTests/stop_after_parsing_abi/err new file mode 100644 index 000000000..9beceafe7 --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_abi/err @@ -0,0 +1 @@ +The following options are mutually exclusive: --stop-after, --abi. Select at most one. diff --git a/test/cmdlineTests/stop_after_parsing_abi/exit b/test/cmdlineTests/stop_after_parsing_abi/exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_abi/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/stop_after_parsing_abi/input.sol b/test/cmdlineTests/stop_after_parsing_abi/input.sol new file mode 100644 index 000000000..978517b3c --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_abi/input.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity *; + +import "A"; + +contract C { + function f() public {} +} diff --git a/test/cmdlineTests/stop_after_parsing_ast/args b/test/cmdlineTests/stop_after_parsing_ast/args new file mode 100644 index 000000000..72df9974a --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_ast/args @@ -0,0 +1 @@ +--pretty-json --json-indent 4 --stop-after parsing --ast-compact-json diff --git a/test/cmdlineTests/stop_after_parsing_ast/input.sol b/test/cmdlineTests/stop_after_parsing_ast/input.sol new file mode 100644 index 000000000..e78a24ff7 --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_ast/input.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity *; + +import "A"; + +contract C {} diff --git a/test/cmdlineTests/stop_after_parsing_ast/output b/test/cmdlineTests/stop_after_parsing_ast/output new file mode 100644 index 000000000..163941860 --- /dev/null +++ b/test/cmdlineTests/stop_after_parsing_ast/output @@ -0,0 +1,48 @@ +JSON AST (compact format): + + +======= stop_after_parsing_ast/input.sol ======= +{ + "absolutePath": "stop_after_parsing_ast/input.sol", + "id": 4, + "license": "GPL-3.0", + "nodeType": "SourceUnit", + "nodes": + [ + { + "id": 1, + "literals": + [ + "solidity", + "*" + ], + "nodeType": "PragmaDirective", + "src": "36:18:0" + }, + { + "absolutePath": "A", + "file": "A", + "id": 2, + "nameLocation": "-1:-1:-1", + "nodeType": "ImportDirective", + "src": "56:11:0", + "symbolAliases": [], + "unitAlias": "" + }, + { + "abstract": false, + "baseContracts": [], + "contractDependencies": [], + "contractKind": "contract", + "id": 3, + "name": "C", + "nameLocation": "78:1:0", + "nodeType": "ContractDefinition", + "nodes": [], + "src": "69:13:0", + "usedErrors": [], + "usedEvents": [] + } + ], + "src": "36:47:0" +}