@@ -716,6 +716,10 @@ class EffectAnalyzer {
716716 }
717717
718718 void visitCall (Call* curr) {
719+ if (curr->isReturn ) {
720+ parent.branchesOut = true ;
721+ }
722+
719723 // call.without.effects has no effects.
720724 if (Intrinsics (parent.module ).isCallWithoutEffects (curr)) {
721725 return ;
@@ -753,32 +757,35 @@ class EffectAnalyzer {
753757 }
754758 }
755759 void visitCallIndirect (CallIndirect* curr) {
756- auto * table = getModule ()->getTable (curr->table );
757- if (!Type::isSubType (Type (curr->heapType , Nullability::Nullable), table->type )) {
760+ auto * table = parent.module .getTable (curr->table );
761+ if (!Type::isSubType (Type (curr->heapType , Nullability::Nullable),
762+ table->type )) {
758763 parent.trap = true ;
759764 return ;
760765 }
766+ if (table->type .isNullable ()) {
767+ parent.implicitTrap = true ;
768+ }
769+ if (curr->isReturn ) {
770+ parent.branchesOut = true ;
771+ }
761772
762773 if (auto it = parent.module .typeEffects .find (curr->heapType );
763- it != parent.module .typeEffects .end ()) {
764- parent.mergeIn (*it->second );
765-
766- if (table->type .isNullable ()) {
767- parent.implicitTrap = true ;
768- }
774+ it != parent.module .typeEffects .end () && it->second ) {
775+ populateEffectsFromGlobalEffects (*it->second , curr);
769776 return ;
770777 }
771778
772779 parent.calls = true ;
773- if (curr->isReturn ) {
774- parent.branchesOut = true ;
775- if (parent.features .hasExceptionHandling ()) {
780+ // If EH is enabled and we don't have global effects information,
781+ // assume that the call body may throw.
782+ if (parent.features .hasExceptionHandling ()) {
783+ if (curr->isReturn ) {
776784 parent.hasReturnCallThrow = true ;
777785 }
778- }
779- if (parent.features .hasExceptionHandling () &&
780- (parent.tryDepth == 0 && !curr->isReturn )) {
781- parent.throws_ = true ;
786+ if (parent.tryDepth == 0 && !curr->isReturn ) {
787+ parent.throws_ = true ;
788+ }
782789 }
783790 }
784791 void visitLocalGet (LocalGet* curr) {
@@ -1042,37 +1049,28 @@ class EffectAnalyzer {
10421049 return ;
10431050 }
10441051
1045- const EffectAnalyzer* targetEffects = nullptr ;
1046- if (auto it =
1047- parent.module .typeEffects .find (curr->target ->type .getHeapType ());
1048- it != parent.module .typeEffects .end ()) {
1049- targetEffects = it->second .get ();
1050- parent.mergeIn (*it->second );
1051- }
1052-
10531052 if (curr->isReturn ) {
10541053 parent.branchesOut = true ;
1055- // When EH is enabled, any call can throw.
1056- if (parent.features .hasExceptionHandling () &&
1057- (!targetEffects || targetEffects->throws ())) {
1058- parent.hasReturnCallThrow = true ;
1059- }
10601054 }
10611055
1062- if (targetEffects) {
1056+ if (auto it =
1057+ parent.module .typeEffects .find (curr->target ->type .getHeapType ());
1058+ it != parent.module .typeEffects .end () && it->second ) {
1059+ populateEffectsFromGlobalEffects (*it->second , curr);
10631060 return ;
10641061 }
1062+ parent.calls = true ;
10651063
1066- if (curr->isReturn ) {
1067- parent.branchesOut = true ;
1068- if (parent.features .hasExceptionHandling ()) {
1064+ // If EH is enabled and we don't have global effects information,
1065+ // assume that the call body may throw.
1066+ if (parent.features .hasExceptionHandling ()) {
1067+ if (curr->isReturn ) {
10691068 parent.hasReturnCallThrow = true ;
10701069 }
1071- }
1072- parent.calls = true ;
1073- if (parent.features .hasExceptionHandling () &&
1074- (parent.tryDepth == 0 && !curr->isReturn )) {
1075- parent.throws_ = true ;
1070+
1071+ if (parent.tryDepth == 0 && !curr->isReturn ) {
1072+ parent.throws_ = true ;
1073+ }
10761074 }
10771075 }
10781076 void visitRefTest (RefTest* curr) {}
@@ -1357,11 +1355,11 @@ class EffectAnalyzer {
13571355 }
13581356 }
13591357
1360- private:
1361- template <typename Call>
1362- bool populateEffectsFromGlobalEffects (const EffectAnalyzer& effects, const Call* curr) {
1358+ private:
1359+ template <typename CallType>
1360+ void populateEffectsFromGlobalEffects (const EffectAnalyzer& effects,
1361+ const CallType* curr) {
13631362 if (curr->isReturn ) {
1364- parent.branchesOut = true ;
13651363 if (effects.throws ()) {
13661364 parent.hasReturnCallThrow = true ;
13671365 }
@@ -1372,7 +1370,6 @@ class EffectAnalyzer {
13721370 filteredEffects.throws_ = false ;
13731371 parent.mergeIn (filteredEffects);
13741372 } else {
1375- // Just merge in all the effects.
13761373 parent.mergeIn (effects);
13771374 }
13781375 }
0 commit comments