Commit c3dfd34
authored
[WebAssembly] Add unreachable before catch destinations (llvm#123915)
When `try_table`'s catch clause's destination has a return type, as in
the case of catch with a concrete tag, catch_ref, and catch_all_ref. For
example:
```wasm
block exnref
try_table (catch_all_ref 0)
...
end_try_table
end_block
... use exnref ...
```
This code is not valid because the block's body type is not exnref. So
we add an unreachable after the 'end_try_table' to make the code valid
here:
```wasm
block exnref
try_table (catch_all_ref 0)
...
end_try_table
unreachable ;; Newly added
end_block
```
Because 'unreachable' is a terminator we also need to split the BB.
---
We need to handle the same thing for unwind mismatch handling. In the
code below, we create a "trampoline BB" that will be the destination for
the nested `try_table`~`end_try_table` added to fix a unwind mismatch:
```wasm
try_table (catch ... )
block exnref
...
try_table (catch_all_ref N)
some code
end_try_table
...
end_block ;; Trampoline BB
throw_ref
end_try_table
```
While the `block` added for the trampoline BB has the return type
`exnref`, its body, which contains the nested `try_table` and other
code, wouldn't have the `exnref` return type. Most times it didn't
become a problem because the block's body ended with something like `br`
or `return`, but that may not always be the case, especially when there
is a loop. So we add an `unreachable` to make the code valid here too:
```wasm
try_table (catch ... )
block exnref
...
try_table (catch_all_ref N)
some code
end_try_table
...
unreachable ;; Newly added
end_block ;; Trampoline BB
throw_ref
end_try_table
```
In this case we just append the `unreachable` at the end of the layout
predecessor BB. (This was tricky to do in the first (non-mismatch) case
because there `end_try_table` and `end_block` were added in the
beginning of an EH pad in `placeTryTableMarker` and moving
`end_try_table` and the new `unreachable` to the previous BB caused
other problems.)
---
This adds many `unreaachable`s to the output, but this adds
`unreachable` to only a few places to see if this is working. The
FileCheck lines in `exception.ll` and `cfg-stackify-eh.ll` are already
heavily redacted to only leave important control-flow instructions, so I
don't think it's worth adding `unreachable`s everywhere.1 parent 5d8390d commit c3dfd34
File tree
5 files changed
+93
-21
lines changed- llvm
- lib/Target/WebAssembly
- test/CodeGen/WebAssembly
5 files changed
+93
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1297 | 1297 | | |
1298 | 1298 | | |
1299 | 1299 | | |
| 1300 | + | |
1300 | 1301 | | |
1301 | 1302 | | |
1302 | 1303 | | |
| |||
1358 | 1359 | | |
1359 | 1360 | | |
1360 | 1361 | | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1361 | 1369 | | |
1362 | 1370 | | |
1363 | 1371 | | |
| |||
1465 | 1473 | | |
1466 | 1474 | | |
1467 | 1475 | | |
1468 | | - | |
| 1476 | + | |
1469 | 1477 | | |
1470 | 1478 | | |
1471 | 1479 | | |
| |||
1523 | 1531 | | |
1524 | 1532 | | |
1525 | 1533 | | |
1526 | | - | |
1527 | | - | |
1528 | | - | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
1529 | 1537 | | |
1530 | 1538 | | |
1531 | 1539 | | |
| |||
1538 | 1546 | | |
1539 | 1547 | | |
1540 | 1548 | | |
1541 | | - | |
1542 | | - | |
| 1549 | + | |
| 1550 | + | |
1543 | 1551 | | |
1544 | | - | |
| 1552 | + | |
1545 | 1553 | | |
1546 | 1554 | | |
1547 | 1555 | | |
| |||
1555 | 1563 | | |
1556 | 1564 | | |
1557 | 1565 | | |
1558 | | - | |
| 1566 | + | |
1559 | 1567 | | |
1560 | | - | |
| 1568 | + | |
1561 | 1569 | | |
1562 | | - | |
| 1570 | + | |
1563 | 1571 | | |
1564 | 1572 | | |
1565 | 1573 | | |
| |||
1943 | 1951 | | |
1944 | 1952 | | |
1945 | 1953 | | |
1946 | | - | |
1947 | | - | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
1948 | 1964 | | |
1949 | 1965 | | |
1950 | 1966 | | |
| |||
2179 | 2195 | | |
2180 | 2196 | | |
2181 | 2197 | | |
2182 | | - | |
2183 | | - | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
2184 | 2207 | | |
2185 | 2208 | | |
2186 | 2209 | | |
| |||
2372 | 2395 | | |
2373 | 2396 | | |
2374 | 2397 | | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
2375 | 2440 | | |
2376 | 2441 | | |
2377 | 2442 | | |
| |||
2398 | 2463 | | |
2399 | 2464 | | |
2400 | 2465 | | |
2401 | | - | |
2402 | 2466 | | |
2403 | 2467 | | |
2404 | | - | |
2405 | | - | |
2406 | | - | |
2407 | | - | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
2408 | 2477 | | |
2409 | 2478 | | |
2410 | 2479 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
| 860 | + | |
860 | 861 | | |
861 | 862 | | |
862 | 863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
0 commit comments