Skip to content

Commit 7ea985d

Browse files
committed
Error when ethdebug is used with optimization.
1 parent 1832fbd commit 7ea985d

File tree

37 files changed

+2362
-373
lines changed

37 files changed

+2362
-373
lines changed

libsolidity/interface/StandardCompiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,9 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
12041204
)
12051205
return formatFatalError(Error::Type::FatalError, "'settings.debug.debugInfo' can only include 'ethdebug', if output 'ir', 'irOptimized', 'evm.bytecode.ethdebug', or 'evm.deployedBytecode.ethdebug' was selected.");
12061206

1207+
if (isEthdebugRequested(ret.outputSelection) && (ret.optimiserSettings.runYulOptimiser || isArtifactRequested(ret.outputSelection, "*", "*", "irOptimized", false)))
1208+
return formatFatalError(Error::Type::FatalError, "Optimization is not yet supported with ethdebug.");
1209+
12071210
return {std::move(ret)};
12081211
}
12091212

solc/CommandLineParser.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,15 +1485,18 @@ void CommandLineParser::processArgs()
14851485
);
14861486

14871487
bool incompatibleEthdebugOutputs =
1488-
m_options.compiler.outputs.asmJson || m_options.compiler.outputs.irAstJson || m_options.compiler.outputs.irOptimizedAstJson;
1488+
m_options.compiler.outputs.asmJson || m_options.compiler.outputs.irAstJson || m_options.compiler.outputs.irOptimizedAstJson ||
1489+
m_options.compiler.outputs.irOptimized || m_options.optimizer.optimizeYul || m_options.optimizer.optimizeEvmasm;
14891490

14901491
bool incompatibleEthdebugInputs = m_options.input.mode != InputMode::Compiler;
14911492

14921493
static std::string enableEthdebugMessage =
14931494
"--" + CompilerOutputs::componentName(&CompilerOutputs::ethdebug) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::ethdebugRuntime);
14941495

1495-
static std::string enableIrMessage =
1496-
"--" + CompilerOutputs::componentName(&CompilerOutputs::ir) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized);
1496+
static std::string incompatibleEthdebugOptimizerMessage =
1497+
"--" + g_strOptimize + " / --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized);
1498+
1499+
static std::string enableIrMessage = "--" + CompilerOutputs::componentName(&CompilerOutputs::ir);
14971500

14981501
if (m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime)
14991502
{
@@ -1506,7 +1509,7 @@ void CommandLineParser::processArgs()
15061509
if (incompatibleEthdebugOutputs)
15071510
solThrow(
15081511
CommandLineValidationError,
1509-
enableEthdebugMessage + " output can only be used with " + enableIrMessage + "."
1512+
enableEthdebugMessage + " output can only be used with " + enableIrMessage + ". Optimization is not yet supported with ethdebug, e.g. no support for " + incompatibleEthdebugOptimizerMessage + " yet."
15101513
);
15111514

15121515
if (!m_options.output.debugInfoSelection.has_value())
@@ -1526,11 +1529,11 @@ void CommandLineParser::processArgs()
15261529

15271530
if (
15281531
m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug &&
1529-
(!(m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized || m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime) || incompatibleEthdebugOutputs)
1532+
(!(m_options.compiler.outputs.ir || m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime) || incompatibleEthdebugOutputs)
15301533
)
15311534
solThrow(
15321535
CommandLineValidationError,
1533-
"--debug-info ethdebug can only be used with " + enableIrMessage + " and/or " + enableEthdebugMessage + "."
1536+
"--debug-info ethdebug can only be used with " + enableIrMessage + " and/or " + enableEthdebugMessage + ". Optimization is not yet supported with ethdebug, e.g. no support for " + incompatibleEthdebugOptimizerMessage + " yet."
15341537
);
15351538

15361539
if (m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug && incompatibleEthdebugInputs)

test/cmdlineTests/ethdebug/args

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--ethdebug --via-ir --optimize --ir-optimized
1+
--ethdebug --via-ir --ir

test/cmdlineTests/ethdebug/output

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,120 @@
22
{"sources":["ethdebug/input.sol"]}
33

44
======= ethdebug/input.sol:C =======
5-
Optimized IR:
5+
IR:
66
/// ethdebug: enabled
77
/// @use-src 0:"ethdebug/input.sol"
88
object "C_6" {
99
code {
10-
{
10+
/// @src 0:60:101 "contract C {..."
11+
mstore(64, memoryguard(128))
12+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
13+
14+
constructor_C_6()
15+
16+
let _1 := allocate_unbounded()
17+
codecopy(_1, dataoffset("C_6_deployed"), datasize("C_6_deployed"))
18+
19+
return(_1, datasize("C_6_deployed"))
20+
21+
function allocate_unbounded() -> memPtr {
22+
memPtr := mload(64)
23+
}
24+
25+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
26+
revert(0, 0)
27+
}
28+
29+
/// @src 0:60:101 "contract C {..."
30+
function constructor_C_6() {
31+
1132
/// @src 0:60:101 "contract C {..."
12-
let _1 := memoryguard(0x80)
13-
mstore(64, _1)
14-
if callvalue() { revert(0, 0) }
15-
let _2 := datasize("C_6_deployed")
16-
codecopy(_1, dataoffset("C_6_deployed"), _2)
17-
return(_1, _2)
33+
1834
}
35+
/// @src 0:60:101 "contract C {..."
36+
1937
}
2038
/// @use-src 0:"ethdebug/input.sol"
2139
object "C_6_deployed" {
2240
code {
41+
/// @src 0:60:101 "contract C {..."
42+
mstore(64, memoryguard(128))
43+
44+
if iszero(lt(calldatasize(), 4))
2345
{
24-
/// @src 0:60:101 "contract C {..."
25-
if iszero(lt(calldatasize(), 4))
46+
let selector := shift_right_224_unsigned(calldataload(0))
47+
switch selector
48+
49+
case 0x26121ff0
2650
{
27-
if eq(0x26121ff0, shr(224, calldataload(0)))
28-
{
29-
if callvalue() { revert(0, 0) }
30-
if slt(add(calldatasize(), not(3)), 0) { revert(0, 0) }
31-
return(0, 0)
32-
}
51+
// f()
52+
53+
external_fun_f_5()
3354
}
55+
56+
default {}
57+
}
58+
59+
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
60+
61+
function shift_right_224_unsigned(value) -> newValue {
62+
newValue :=
63+
64+
shr(224, value)
65+
66+
}
67+
68+
function allocate_unbounded() -> memPtr {
69+
memPtr := mload(64)
70+
}
71+
72+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
3473
revert(0, 0)
3574
}
75+
76+
function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() {
77+
revert(0, 0)
78+
}
79+
80+
function abi_decode_tuple_(headStart, dataEnd) {
81+
if slt(sub(dataEnd, headStart), 0) { revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() }
82+
83+
}
84+
85+
function abi_encode_tuple__to__fromStack(headStart ) -> tail {
86+
tail := add(headStart, 0)
87+
88+
}
89+
90+
function external_fun_f_5() {
91+
92+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
93+
abi_decode_tuple_(4, calldatasize())
94+
fun_f_5()
95+
let memPos := allocate_unbounded()
96+
let memEnd := abi_encode_tuple__to__fromStack(memPos )
97+
return(memPos, sub(memEnd, memPos))
98+
99+
}
100+
101+
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() {
102+
revert(0, 0)
103+
}
104+
105+
/// @ast-id 5
106+
/// @src 0:77:99 "function f() public {}"
107+
function fun_f_5() {
108+
109+
}
110+
/// @src 0:60:101 "contract C {..."
111+
36112
}
113+
37114
data ".metadata" hex"<BYTECODE REMOVED>"
38115
}
116+
39117
}
40118

119+
41120
Debug Data (ethdebug/format/program):
42121
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--ethdebug-runtime --ethdebug --via-ir --optimize --ir-optimized
1+
--ethdebug-runtime --ethdebug --via-ir --ir

test/cmdlineTests/ethdebug_and_ethdebug_runtime/output

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,121 @@
22
{"sources":["ethdebug_and_ethdebug_runtime/input.sol"]}
33

44
======= ethdebug_and_ethdebug_runtime/input.sol:C =======
5-
Optimized IR:
5+
IR:
66
/// ethdebug: enabled
77
/// @use-src 0:"ethdebug_and_ethdebug_runtime/input.sol"
88
object "C_6" {
99
code {
10-
{
10+
/// @src 0:60:101 "contract C {..."
11+
mstore(64, memoryguard(128))
12+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
13+
14+
constructor_C_6()
15+
16+
let _1 := allocate_unbounded()
17+
codecopy(_1, dataoffset("C_6_deployed"), datasize("C_6_deployed"))
18+
19+
return(_1, datasize("C_6_deployed"))
20+
21+
function allocate_unbounded() -> memPtr {
22+
memPtr := mload(64)
23+
}
24+
25+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
26+
revert(0, 0)
27+
}
28+
29+
/// @src 0:60:101 "contract C {..."
30+
function constructor_C_6() {
31+
1132
/// @src 0:60:101 "contract C {..."
12-
let _1 := memoryguard(0x80)
13-
mstore(64, _1)
14-
if callvalue() { revert(0, 0) }
15-
let _2 := datasize("C_6_deployed")
16-
codecopy(_1, dataoffset("C_6_deployed"), _2)
17-
return(_1, _2)
33+
1834
}
35+
/// @src 0:60:101 "contract C {..."
36+
1937
}
2038
/// @use-src 0:"ethdebug_and_ethdebug_runtime/input.sol"
2139
object "C_6_deployed" {
2240
code {
41+
/// @src 0:60:101 "contract C {..."
42+
mstore(64, memoryguard(128))
43+
44+
if iszero(lt(calldatasize(), 4))
2345
{
24-
/// @src 0:60:101 "contract C {..."
25-
if iszero(lt(calldatasize(), 4))
46+
let selector := shift_right_224_unsigned(calldataload(0))
47+
switch selector
48+
49+
case 0x26121ff0
2650
{
27-
if eq(0x26121ff0, shr(224, calldataload(0)))
28-
{
29-
if callvalue() { revert(0, 0) }
30-
if slt(add(calldatasize(), not(3)), 0) { revert(0, 0) }
31-
return(0, 0)
32-
}
51+
// f()
52+
53+
external_fun_f_5()
3354
}
55+
56+
default {}
57+
}
58+
59+
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
60+
61+
function shift_right_224_unsigned(value) -> newValue {
62+
newValue :=
63+
64+
shr(224, value)
65+
66+
}
67+
68+
function allocate_unbounded() -> memPtr {
69+
memPtr := mload(64)
70+
}
71+
72+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
3473
revert(0, 0)
3574
}
75+
76+
function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() {
77+
revert(0, 0)
78+
}
79+
80+
function abi_decode_tuple_(headStart, dataEnd) {
81+
if slt(sub(dataEnd, headStart), 0) { revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() }
82+
83+
}
84+
85+
function abi_encode_tuple__to__fromStack(headStart ) -> tail {
86+
tail := add(headStart, 0)
87+
88+
}
89+
90+
function external_fun_f_5() {
91+
92+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
93+
abi_decode_tuple_(4, calldatasize())
94+
fun_f_5()
95+
let memPos := allocate_unbounded()
96+
let memEnd := abi_encode_tuple__to__fromStack(memPos )
97+
return(memPos, sub(memEnd, memPos))
98+
99+
}
100+
101+
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() {
102+
revert(0, 0)
103+
}
104+
105+
/// @ast-id 5
106+
/// @src 0:77:99 "function f() public {}"
107+
function fun_f_5() {
108+
109+
}
110+
/// @src 0:60:101 "contract C {..."
111+
36112
}
113+
37114
data ".metadata" hex"<BYTECODE REMOVED>"
38115
}
116+
39117
}
40118

119+
41120
Debug Data (ethdebug/format/program):
42121
{}
43122
Debug Data of the runtime part (ethdebug/format/program):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--ethdebug --via-ir --optimize --ir-optimized
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error: --ethdebug / --ethdebug-runtime output can only be used with --ir. Optimization is not yet supported with ethdebug, e.g. no support for --optimize / --ir-optimized yet.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
pragma solidity >=0.0;
3+
4+
contract C {
5+
function f() public {}
6+
}
7+

0 commit comments

Comments
 (0)