This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] In optional model, implement `widen` and make `compare` sound.
ClosedPublic

Authored by ymandel on Dec 19 2022, 1:00 PM.

Details

Summary

This patch includes two related changes:

  1. Rewrite compare operation to be sound. Current version checks for equality

of isNonEmptyOptional on both values, judging the values Same when the
results are equal. While that works when both are true, it is problematic when
they are both false, because there are four cases in which that's can occur:
both empty, one empty and one unknown (which is two cases), and both unknown. In
the latter three cases, it is unsound to judge them Same. This patch changes
compare to explicitly check for case of both empty and then judge any other
case Different.

  1. With the change to compare, a number of common cases will no longer

terminate. So, we also implement widening to properly handle those cases and
recover termination.

Drive-by: improve performance of merge operation.

Of the new tests, the code before the patch fails

  • ReassignValueInLoopToSetUnsafe, and
  • ReassignValueInLoopToUnknownUnsafe.

Diff Detail

Event Timeline

ymandel created this revision.Dec 19 2022, 1:00 PM
Herald added a project: Restricted Project. · View Herald Transcript
ymandel requested review of this revision.Dec 19 2022, 1:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 1:00 PM
gribozavr2 accepted this revision.Dec 19 2022, 1:48 PM
This revision is now accepted and ready to land.Dec 19 2022, 1:48 PM
xazax.hun accepted this revision.Dec 19 2022, 2:55 PM
This revision was landed with ongoing or failed builds.Jan 12 2023, 12:37 PM
This revision was automatically updated to reflect the committed changes.