Skip to content

Commit 7334420

Browse files
authored
Merge pull request #12193 from ethereum/use-src-ewasm-crash
Fix crash when using @use-src while compiling yul -> ewasm
2 parents 969707c + 49b4e77 commit 7334420

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Compiler Features:
77

88

99
Bugfixes:
10+
* Code Generator: Fix a crash when using ``@use-src`` and compiling from Yul to ewasm.
1011

1112

1213
### 0.8.10 (2021-11-09)

libyul/backends/wasm/EVMToEwasmTranslator.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ void EVMToEwasmTranslator::parsePolyfill()
137137
string(solidity::yul::wasm::polyfill::Logical) +
138138
string(solidity::yul::wasm::polyfill::Memory) +
139139
"}", "");
140-
m_polyfill = Parser(errorReporter, WasmDialect::instance()).parse(charStream);
140+
141+
// Passing an empty SourceLocation() here is a workaround to prevent a crash
142+
// when compiling from yul->ewasm. We're stripping nativeLocation and
143+
// originLocation from the AST (but we only really need to strip nativeLocation)
144+
m_polyfill = Parser(errorReporter, WasmDialect::instance(), langutil::SourceLocation()).parse(charStream);
141145
if (!errors.empty())
142146
{
143147
string message;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--strict-assembly --yul-dialect evm --machine ewasm --optimize --ewasm-ir
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warning: Yul is still experimental. Please use the output with care.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// @use-src 0:"test.sol"
2+
object "C" {
3+
code { sstore(0,0) }
4+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
======= yul_to_wasm_source_location_crash/input.yul (Ewasm) =======
3+
4+
==========================
5+
6+
Translated source:
7+
/// @use-src 0:"test.sol"
8+
object "C" {
9+
code {
10+
function main()
11+
{
12+
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
13+
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
14+
i64.store(0:i32, y)
15+
i64.store(i32.add(0:i32, 8:i32), y)
16+
i64.store(i32.add(0:i32, 16:i32), y)
17+
i64.store(i32.add(0:i32, 24:i32), y)
18+
i64.store(32:i32, y)
19+
i64.store(i32.add(32:i32, 8:i32), y)
20+
i64.store(i32.add(32:i32, 16:i32), y)
21+
i64.store(i32.add(32:i32, 24:i32), y)
22+
eth.storageStore(0:i32, 32:i32)
23+
}
24+
function bswap16(x:i32) -> y:i32
25+
{
26+
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
27+
}
28+
function bswap32(x:i32) -> y:i32
29+
{
30+
let hi:i32 := i32.shl(bswap16(x), 16:i32)
31+
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)