@@ -116,20 +116,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
116116 wrapAddress64 (curr->ptr , curr->memory );
117117 }
118118
119- void visitMemory (Memory* memory) {
120- // This is visited last.
121- seenMemory = true ;
122- if (memory->is64 ()) {
123- memory->indexType = Type::i32 ;
124- if (memory->hasMax () && memory->max > Memory::kMaxSize32 ) {
125- memory->max = Memory::kMaxSize32 ;
126- }
127- }
128- }
129-
130119 void visitDataSegment (DataSegment* segment) {
131- // We assume that memories are visited after segments, so assert that here.
132- assert (!seenMemory);
133120 auto & module = *getModule ();
134121
135122 // passive segments don't have any offset to adjust
@@ -172,10 +159,19 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
172159 return ;
173160 }
174161 super::run (module );
162+ // Don't modify the memories themselves until after the traversal since we
163+ // that would require memories to be the last thing that get visited, and
164+ // we don't want to depend on that specific ordering.
165+ for (auto & memory : module ->memories ) {
166+ if (memory->is64 ()) {
167+ memory->indexType = Type::i32 ;
168+ if (memory->hasMax () && memory->max > Memory::kMaxSize32 ) {
169+ memory->max = Memory::kMaxSize32 ;
170+ }
171+ }
172+ }
175173 module ->features .disable (FeatureSet::Memory64);
176174 }
177-
178- bool seenMemory = false ;
179175};
180176
181177Pass* createMemory64LoweringPass () { return new Memory64Lowering (); }
0 commit comments