Commit e3adbad
authored
Fix TypeGeneralizing stack corruption and crash (WebAssembly#8310)
## Summary
Two bugs in the experimental `TypeGeneralizing` pass's backward
analysis:
### 1. `visitStructSet` pushes non-ref field types onto the stack
`visitStructSet` unconditionally pushes the struct field type as a type
requirement onto the backward analysis stack (line 690). When the field
is a non-reference type (i32, f64, etc.), this corrupts the stack
because non-ref producers (like `visitConst`, `visitBinary`) are no-ops
that don't pop. The spurious non-ref value on the stack causes
subsequent `pop()` calls to retrieve wrong type requirements.
The analogous methods all correctly guard with `isRef()`:
- `visitArraySet` (line 792): `if (elemType.isRef())`
- `visitStructNew` (line 620): `if (field.type.isRef())`
- `handleCall` (line 364): `if (param.isRef())`
**Fix:** Add `if (fieldType.isRef())` guard before pushing.
### 2. `visitRefAs` crashes on `Type::none` from empty stack
When the backward analysis stack is empty (no downstream consumer
imposes a type requirement), `pop()` returns `Type::none`. `visitRefAs`
then calls `type.getHeapType()` on `Type::none`, triggering
`assert(isRef())` — crashing on any `ref.as_non_null` whose result is
dropped.
**Fix:** Check for `Type::none` before accessing heap type, and
propagate "no requirement" through.
Both bugs are in the experimental (not-yet-sound) pass and do not affect
production optimization pipelines.
## Test plan
- [x] New lit test `type-generalizing-fixes.wast` covering:
- `struct.set` on non-ref field followed by ref field (stack alignment)
- `drop(ref.as_non_null(...))` (empty stack crash)
- `drop(any.convert_extern(extern.convert_any(...)))` (empty stack with
convert ops)
- [x] All 309 unit tests pass1 parent f5ea49a commit e3adbad
File tree
2 files changed
+92
-1
lines changed- src/passes
- test/lit/passes
2 files changed
+92
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
690 | | - | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
691 | 694 | | |
692 | 695 | | |
693 | 696 | | |
| |||
861 | 864 | | |
862 | 865 | | |
863 | 866 | | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
864 | 872 | | |
865 | 873 | | |
866 | 874 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
0 commit comments