Skip to content

Commit 04930ab

Browse files
authored
[GC] Fix name updating in GTO when only some fields are named (#7986)
When updating field names, that pass looped over the number of field names. If all fields are named, that is fine, but if only some are, we did not reach later ones. Fixes #7982
1 parent 84795e3 commit 04930ab

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/passes/GlobalTypeOptimization.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,13 @@ struct GlobalTypeOptimization : public Pass {
444444

445445
// Clear the old names and write the new ones.
446446
nameInfo.fieldNames.clear();
447-
for (Index i = 0; i < oldFieldNames.size(); i++) {
447+
for (Index i = 0; i < indexesAfterRemoval.size(); i++) {
448448
auto newIndex = indexesAfterRemoval[i];
449-
if (newIndex != RemovedField && oldFieldNames.count(i)) {
450-
assert(oldFieldNames[i].is());
451-
nameInfo.fieldNames[newIndex] = oldFieldNames[i];
449+
if (newIndex != RemovedField) {
450+
auto iter = oldFieldNames.find(i);
451+
if (iter != oldFieldNames.end()) {
452+
nameInfo.fieldNames[newIndex] = iter->second;
453+
}
452454
}
453455
}
454456
}

test/lit/passes/gto-removals.wast

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,3 +1675,45 @@
16751675
)
16761676
)
16771677
)
1678+
1679+
(module
1680+
;; A struct with partial names: only some fields are named. We should still
1681+
;; update names properly when removing and reordering.
1682+
1683+
;; CHECK: (rec
1684+
;; CHECK-NEXT: (type $struct (sub (struct (field (mut i32)) (field $named (mut i32)))))
1685+
(type $struct (sub (struct (field (mut i32)) (field (mut i32)) (field $named (mut i32)) (field (mut i32)) (field (mut i32)))))
1686+
1687+
;; CHECK: (type $1 (func (param (ref $struct))))
1688+
1689+
;; CHECK: (func $func (type $1) (param $x (ref $struct))
1690+
;; CHECK-NEXT: (struct.set $struct 0
1691+
;; CHECK-NEXT: (local.get $x)
1692+
;; CHECK-NEXT: (struct.get $struct 0
1693+
;; CHECK-NEXT: (local.get $x)
1694+
;; CHECK-NEXT: )
1695+
;; CHECK-NEXT: )
1696+
;; CHECK-NEXT: (struct.set $struct $named
1697+
;; CHECK-NEXT: (local.get $x)
1698+
;; CHECK-NEXT: (struct.get $struct $named
1699+
;; CHECK-NEXT: (local.get $x)
1700+
;; CHECK-NEXT: )
1701+
;; CHECK-NEXT: )
1702+
;; CHECK-NEXT: )
1703+
(func $func (param $x (ref $struct))
1704+
;; Use fields 1 and 2.
1705+
(struct.set $struct 1
1706+
(local.get $x)
1707+
(struct.get $struct 1
1708+
(local.get $x)
1709+
)
1710+
)
1711+
(struct.set $struct 2
1712+
(local.get $x)
1713+
(struct.get $struct 2
1714+
(local.get $x)
1715+
)
1716+
)
1717+
)
1718+
)
1719+

0 commit comments

Comments
 (0)