diff --git a/Changelog.md b/Changelog.md index 79d5df058..b3af54d04 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ Compiler Features: Bugfixes: + * Code Generator: Fix a crash when using ``@use-src`` and compiling from Yul to ewasm. ### 0.8.10 (2021-11-09) diff --git a/libyul/backends/wasm/EVMToEwasmTranslator.cpp b/libyul/backends/wasm/EVMToEwasmTranslator.cpp index eb7a60a32..359cc023b 100644 --- a/libyul/backends/wasm/EVMToEwasmTranslator.cpp +++ b/libyul/backends/wasm/EVMToEwasmTranslator.cpp @@ -137,7 +137,11 @@ void EVMToEwasmTranslator::parsePolyfill() string(solidity::yul::wasm::polyfill::Logical) + string(solidity::yul::wasm::polyfill::Memory) + "}", ""); - m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream); + + // Passing an empty SourceLocation() here is a workaround to prevent a crash + // when compiling from yul->ewasm. We're stripping nativeLocation and + // originLocation from the AST (but we only really need to strip nativeLocation) + m_polyfill = Parser(errorReporter, WasmDialect::instance(), langutil::SourceLocation()).parse(charStream); if (!errors.empty()) { string message; diff --git a/test/cmdlineTests/yul_to_wasm_source_location_crash/args b/test/cmdlineTests/yul_to_wasm_source_location_crash/args new file mode 100644 index 000000000..254a1883c --- /dev/null +++ b/test/cmdlineTests/yul_to_wasm_source_location_crash/args @@ -0,0 +1 @@ +--strict-assembly --yul-dialect evm --machine ewasm --optimize --ewasm-ir diff --git a/test/cmdlineTests/yul_to_wasm_source_location_crash/err b/test/cmdlineTests/yul_to_wasm_source_location_crash/err new file mode 100644 index 000000000..014a1178f --- /dev/null +++ b/test/cmdlineTests/yul_to_wasm_source_location_crash/err @@ -0,0 +1 @@ +Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/yul_to_wasm_source_location_crash/input.yul b/test/cmdlineTests/yul_to_wasm_source_location_crash/input.yul new file mode 100644 index 000000000..89e060931 --- /dev/null +++ b/test/cmdlineTests/yul_to_wasm_source_location_crash/input.yul @@ -0,0 +1,4 @@ +/// @use-src 0:"test.sol" +object "C" { + code { sstore(0,0) } +} diff --git a/test/cmdlineTests/yul_to_wasm_source_location_crash/output b/test/cmdlineTests/yul_to_wasm_source_location_crash/output new file mode 100644 index 000000000..29ff631aa --- /dev/null +++ b/test/cmdlineTests/yul_to_wasm_source_location_crash/output @@ -0,0 +1,34 @@ + +======= yul_to_wasm_source_location_crash/input.yul (Ewasm) ======= + +========================== + +Translated source: +/// @use-src 0:"test.sol" +object "C" { + code { + function main() + { + let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32) + let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32))))) + i64.store(0:i32, y) + i64.store(i32.add(0:i32, 8:i32), y) + i64.store(i32.add(0:i32, 16:i32), y) + i64.store(i32.add(0:i32, 24:i32), y) + i64.store(32:i32, y) + i64.store(i32.add(32:i32, 8:i32), y) + i64.store(i32.add(32:i32, 16:i32), y) + i64.store(i32.add(32:i32, 24:i32), y) + eth.storageStore(0:i32, 32:i32) + } + function bswap16(x:i32) -> y:i32 + { + y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32)) + } + function bswap32(x:i32) -> y:i32 + { + let hi:i32 := i32.shl(bswap16(x), 16:i32) + y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32))) + } + } +}