Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/passes/GlobalTypeOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,13 @@ struct GlobalTypeOptimization : public Pass {

// Clear the old names and write the new ones.
nameInfo.fieldNames.clear();
for (Index i = 0; i < oldFieldNames.size(); i++) {
for (Index i = 0; i < indexesAfterRemoval.size(); i++) {
auto newIndex = indexesAfterRemoval[i];
if (newIndex != RemovedField && oldFieldNames.count(i)) {
assert(oldFieldNames[i].is());
nameInfo.fieldNames[newIndex] = oldFieldNames[i];
if (newIndex != RemovedField) {
auto iter = oldFieldNames.find(i);
if (iter != oldFieldNames.end()) {
nameInfo.fieldNames[newIndex] = iter->second;
}
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions test/lit/passes/gto-removals.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1675,3 +1675,45 @@
)
)
)

(module
;; A struct with partial names: only some fields are named. We should still
;; update names properly when removing and reordering.

;; CHECK: (rec
;; CHECK-NEXT: (type $struct (sub (struct (field (mut i32)) (field $named (mut i32)))))
(type $struct (sub (struct (field (mut i32)) (field (mut i32)) (field $named (mut i32)) (field (mut i32)) (field (mut i32)))))

;; CHECK: (type $1 (func (param (ref $struct))))

;; CHECK: (func $func (type $1) (param $x (ref $struct))
;; CHECK-NEXT: (struct.set $struct 0
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (struct.get $struct 0
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (struct.set $struct $named
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (struct.get $struct $named
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $func (param $x (ref $struct))
;; Use fields 1 and 2.
(struct.set $struct 1
(local.get $x)
(struct.get $struct 1
(local.get $x)
)
)
(struct.set $struct 2
(local.get $x)
(struct.get $struct 2
(local.get $x)
)
)
)
)

Loading