This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Change PruneTriviallyFalseEdges for building CFG
ClosedPublic

Authored by kinu on May 2 2023, 2:52 AM.

Details

Summary

Keeping this false could end up with extra iterations on a lot of loops
that aren't real ones (e.g. they could be a do-while-false for macros),
and makes the analyses very slow.

This patch changes the default for
CFG::BuildOptions.PruneTriviallyFalseEdges to true to avoid it.

Diff Detail

Event Timeline

kinu created this revision.May 2 2023, 2:52 AM
Herald added a project: Restricted Project. · View Herald Transcript
kinu requested review of this revision.May 2 2023, 2:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 2:52 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kinu edited the summary of this revision. (Show Details)May 2 2023, 2:58 AM
kinu added reviewers: ymandel, xazax.hun, mboehme, gribozavr2.

Is it testable? For example, can we show that we don't compute the program state for the program point "p" here:

void f() {
  while (true) {
  }
  /*p*/
}
kinu updated this revision to Diff 518676.May 2 2023, 3:36 AM

Add a while-true test

kinu added a comment.May 2 2023, 3:37 AM

Is it testable? For example, can we show that we don't compute the program state for the program point "p" here:

I added a simple test, how does it look?

Is it testable? For example, can we show that we don't compute the program state for the program point "p" here:

I added a simple test, how does it look?

Do we even need to add a new test for this?

This change breaks the existing test TransferTest.VarDeclInDoWhile, which tests essentially the same scenario, so it's probably sufficient to just update that test?

gribozavr2 accepted this revision.May 2 2023, 4:06 AM
This revision is now accepted and ready to land.May 2 2023, 4:06 AM
ymandel accepted this revision.May 2 2023, 5:28 AM

Thank you!

kinu updated this revision to Diff 518702.May 2 2023, 6:30 AM

Changing the existing test to reflect the flag change

gribozavr2 added inline comments.May 2 2023, 6:40 AM
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2641

Could you update the test name to reflect what the test is checking now? (the comment that you added below)

mboehme added inline comments.May 2 2023, 6:41 AM
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2673

It's unfortuante that all of these checks have gone away. I think the test was actually trying to test something.

I'd suggest checking the environment at two different places:

void target(int *Foo) {
  do {
    int Bar = *Foo;
    // [[in_loop]]
  } while (true);
  (void)0;
  // [[after_loop]]
}

You can keep the existing checks for the in_loop environment and verify that Results doesn't actually contain an environment for after_loop.

xazax.hun accepted this revision.May 2 2023, 7:51 AM
kinu added a comment.May 2 2023, 8:31 AM

(comment only)

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2673

Wdyt if we change this to exercise do { } while (false) instead (with the checks that we already have), and add a simple while (true) {}?

kinu updated this revision to Diff 518762.May 2 2023, 8:57 AM

Updated changes further not to lose the existing checks with the do-while test.

Also restored the simplest test that exercises the while-true one.

mboehme added inline comments.May 3 2023, 4:08 AM
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2673

Thanks, good idea!

2690

This comment looks stale?

gribozavr2 accepted this revision.May 3 2023, 4:18 AM
kinu updated this revision to Diff 519029.May 3 2023, 4:35 AM

Updated the stale comment.

kinu marked an inline comment as done.May 3 2023, 4:36 AM
kinu added inline comments.
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2690

Good catch, updated!

This revision was landed with ongoing or failed builds.May 3 2023, 11:42 AM
This revision was automatically updated to reflect the committed changes.