Skip to content

Commit 6baf33c

Browse files
Fix for traps never happens
1 parent 7cd76de commit 6baf33c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/ir/effects.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ class EffectAnalyzer {
287287
//
288288
// TODO: Go through the optimizer and use this in all places that do not move
289289
// code around.
290-
bool hasUnremovableSideEffects() const {
291-
return hasNonTrapSideEffects() || (trap && !trapsNeverHappen);
292-
}
290+
bool hasUnremovableSideEffects() const { return hasSideEffects(); }
293291

294292
bool hasAnything() const {
295293
return hasSideEffects() || accessesLocal() || readsMutableGlobalState();
@@ -418,17 +416,10 @@ class EffectAnalyzer {
418416
// anything.
419417
assert(!((trap && other.throws()) || (throws() && other.trap)));
420418
// We can't reorder an implicit trap in a way that could alter what global
421-
// state is modified. However, in trapsNeverHappen mode we assume traps do
422-
// not occur in practice, which lets us ignore this, at least in the case
423-
// that the code executes. As mentioned above, we assume that there is no
424-
// transfer of control flow between the things we are comparing, so all we
425-
// need to do is check for such transfers in them.
426-
if (!trapsNeverHappen || transfersControlFlow() ||
427-
other.transfersControlFlow()) {
428-
if ((trap && other.writesGlobalState()) ||
429-
(other.trap && writesGlobalState())) {
430-
return true;
431-
}
419+
// state is modified.
420+
if ((trap && other.writesGlobalState()) ||
421+
(other.trap && writesGlobalState())) {
422+
return true;
432423
}
433424
return false;
434425
}
@@ -466,6 +457,12 @@ class EffectAnalyzer {
466457
trap = trap || other.trap;
467458
implicitTrap = implicitTrap || other.implicitTrap;
468459
trapsNeverHappen = trapsNeverHappen || other.trapsNeverHappen;
460+
if (trapsNeverHappen) {
461+
trap = false;
462+
implicitTrap = false;
463+
} else if (ignoreImplicitTraps) {
464+
implicitTrap = false;
465+
}
469466
throws_ = throws_ || other.throws_;
470467
danglingPop = danglingPop || other.danglingPop;
471468
mayNotReturn = mayNotReturn || other.mayNotReturn;
@@ -1441,11 +1438,15 @@ class EffectAnalyzer {
14411438
void post() {
14421439
assert(tryDepth == 0);
14431440

1444-
if (ignoreImplicitTraps) {
1441+
if (ignoreImplicitTraps || trapsNeverHappen) {
14451442
implicitTrap = false;
14461443
} else if (implicitTrap) {
14471444
trap = true;
14481445
}
1446+
1447+
if (trapsNeverHappen) {
1448+
trap = false;
1449+
}
14491450
}
14501451
};
14511452

0 commit comments

Comments
 (0)