Skip to content

Commit 0e9802e

Browse files
committed
Prevent crash when translating yul->ewasm with @use-src annotations
1 parent f42e3c0 commit 0e9802e

File tree

6 files changed

+103
-1
lines changed

6 files changed

+103
-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ 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+
m_polyfill = Parser(errorReporter, WasmDialect::instance(), langutil::SourceLocation()).parse(charStream);
141141
if (!errors.empty())
142142
{
143143
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
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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
======= yul_to_wasm_source_location_crash/input.yul (Ewasm) =======
3+
4+
Pretty printed source:
5+
/// @use-src 0:"test.sol"
6+
object "C" {
7+
code { { sstore(0, 0) } }
8+
}
9+
10+
11+
==========================
12+
13+
Translated source:
14+
/// @use-src 0:"test.sol"
15+
object "C" {
16+
code {
17+
function main()
18+
{
19+
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
20+
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
21+
i64.store(0:i32, y)
22+
i64.store(i32.add(0:i32, 8:i32), y)
23+
i64.store(i32.add(0:i32, 16:i32), y)
24+
i64.store(i32.add(0:i32, 24:i32), y)
25+
i64.store(32:i32, y)
26+
i64.store(i32.add(32:i32, 8:i32), y)
27+
i64.store(i32.add(32:i32, 16:i32), y)
28+
i64.store(i32.add(32:i32, 24:i32), y)
29+
eth.storageStore(0:i32, 32:i32)
30+
}
31+
function bswap16(x:i32) -> y:i32
32+
{
33+
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
34+
}
35+
function bswap32(x:i32) -> y:i32
36+
{
37+
let hi:i32 := i32.shl(bswap16(x), 16:i32)
38+
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
39+
}
40+
}
41+
}
42+
43+
44+
Binary representation:
45+
0061736d01000000010e0360000060017f017f60027f7f0002190108657468657265756d0c73746f7261676553746f726500020304030001010503010001060100071102066d656d6f72790200046d61696e00010ab101037001027e02404200a71003ad422086210020004200422088a71003ad84210141002001370000410041086a2001370000410041106a2001370000410041186a200137000041202001370000412041086a2001370000412041106a2001370000412041186a20013700004100412010000b0b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100241107421022002200041107610027221010b20010b
46+
47+
Text representation:
48+
(module
49+
(import "ethereum" "storageStore" (func $eth.storageStore (param i32 i32)))
50+
(memory $memory (export "memory") 1)
51+
(export "main" (func $main))
52+
53+
(func $main
54+
(local $hi i64)
55+
(local $y i64)
56+
(block $label_
57+
(local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.const 0)))) (i64.const 32)))
58+
(local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (i64.const 0) (i64.const 32)))))))
59+
(i64.store (i32.const 0) (local.get $y))
60+
(i64.store (i32.add (i32.const 0) (i32.const 8)) (local.get $y))
61+
(i64.store (i32.add (i32.const 0) (i32.const 16)) (local.get $y))
62+
(i64.store (i32.add (i32.const 0) (i32.const 24)) (local.get $y))
63+
(i64.store (i32.const 32) (local.get $y))
64+
(i64.store (i32.add (i32.const 32) (i32.const 8)) (local.get $y))
65+
(i64.store (i32.add (i32.const 32) (i32.const 16)) (local.get $y))
66+
(i64.store (i32.add (i32.const 32) (i32.const 24)) (local.get $y))
67+
(call $eth.storageStore (i32.const 0) (i32.const 32))
68+
)
69+
)
70+
71+
(func $bswap16
72+
(param $x i32)
73+
(result i32)
74+
(local $y i32)
75+
(block $label__1
76+
(local.set $y (i32.or (i32.and (i32.shl (local.get $x) (i32.const 8)) (i32.const 65280)) (i32.and (i32.shr_u (local.get $x) (i32.const 8)) (i32.const 255))))
77+
78+
)
79+
(local.get $y)
80+
)
81+
82+
(func $bswap32
83+
(param $x i32)
84+
(result i32)
85+
(local $y i32)
86+
(local $hi i32)
87+
(block $label__2
88+
(local.set $hi (i32.shl (call $bswap16 (local.get $x)) (i32.const 16)))
89+
(local.set $y (i32.or (local.get $hi) (call $bswap16 (i32.shr_u (local.get $x) (i32.const 16)))))
90+
91+
)
92+
(local.get $y)
93+
)
94+
95+
)

0 commit comments

Comments
 (0)