@@ -167,12 +167,7 @@ struct FuncData {
167167
168168// The data of a (ref exn) literal.
169169struct ExnData {
170- // The tag of this exn data.
171- // TODO: Add self, like in FuncData, to handle the case of a module that is
172- // instantiated multiple times.
173170 const Tag* tag;
174-
175- // The payload of this exn data.
176171 Literals payload;
177172
178173 ExnData (const Tag* tag, Literals payload) : tag(tag), payload(payload) {}
@@ -4662,7 +4657,14 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
46624657
46634658 // note: allTags[catchTag] will be null if it's a tag that we don't know
46644659 // about, i.e. an unimported tag.
4665- // Pointer comparison.
4660+ // We do a pointer comparison here (`tag->second == exnData->tag`)
4661+ // because a tag just consists of a signature, and two tags may look the
4662+ // same but have different identities, e.g. given
4663+ // (tag $a (param i32))
4664+ // (tag $b (param i32))
4665+ // a catch clause for $b won't catch $a and vice versa.
4666+ // This can also happen when a module is instantiated twice and the same
4667+ // tag is imported from each instance. See the instance.wast spec test.
46664668 if (auto tag = allTags.find (catchTag);
46674669 !catchTag.is () ||
46684670 ((tag != allTags.end ()) && tag->second == exnData->tag )) {
0 commit comments