This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Clarify requirements for zero-stride to be UB
ClosedPublic

Authored by reames on Aug 31 2021, 3:23 PM.

Details

Summary

There's a silent bug in our reasoning about zero strides. We assume that having a single static exit implies that if that exit is not taken, then the loop must be infinite. This ignores the potential for abnormal exits via exceptions. Consider the following example:
for (uint_8 i = 0; i < 1; i += 0) {

throw_on_thousandth_call();

}

Our reasoning is such that we'd conclude this loop can't take the backedge as that would lead to a (presumed) infinite loop.

In practice, this is a silent bug because the loopIsFiniteByAssumption returns false strictly more often than the loopHaNoAbnormalExits property. We could reasonable want to change that in the future, so fixing the codeflow now is worthwhile.

Diff Detail

Event Timeline

reames created this revision.Aug 31 2021, 3:23 PM
reames requested review of this revision.Aug 31 2021, 3:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2021, 3:23 PM
efriedma accepted this revision.Sep 1 2021, 1:48 PM

LGTM.

If a loop is finite by assumption, it doesn't have external side-effects. But then, how do we exit the loop? I guess throwing an exception doesn't involve an external side-effect. But we don't really have any incentive to try to model that, given that every place we call loopIsFiniteByAssumption() also calls loopHasNoAbnormalExits(), so this seems like it will stay a theoretical problem. I guess it serves as documentation, though.

This revision is now accepted and ready to land.Sep 1 2021, 1:48 PM
This revision was automatically updated to reflect the committed changes.