-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[dataflow] CXXForRangeStmt should extend flow condition #80989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1710,4 +1710,25 @@ TEST_F(TopTest, ForRangeStmtConverges) { | |||||||
// analysis converged. | ||||||||
}); | ||||||||
} | ||||||||
|
||||||||
TEST_F(TopTest, ForRangeStmtHasFlowCondition) { | ||||||||
std::string Code = R"( | ||||||||
#include <array> | ||||||||
void target(bool Foo) { | ||||||||
std::array<int, 5> t; | ||||||||
for (auto& i : t) { | ||||||||
(void)0; | ||||||||
/*[[p1]]*/ | ||||||||
} | ||||||||
} | ||||||||
)"; | ||||||||
runDataflow(Code, | ||||||||
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, | ||||||||
const AnalysisOutputs &AO) { | ||||||||
ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1")); | ||||||||
const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1"); | ||||||||
Comment on lines
+1728
to
+1729
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
ASSERT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken()))); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It obviously doesn't make a difference in this case, but a) it's good style to default to |
||||||||
}); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this fail without the other changes in this PR? If it does, this looks to me more like a bug in |
||||||||
} | ||||||||
Comment on lines
+1714
to
+1732
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this test work @martinboehme ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comments above -- I'm not sure that the test, if it fails, means that we need a flow condition for the range-based for. (User code will never be able to "observe" this flow condition, so I'm not sure why we need it.) I still don't understand what the underlying purpose is that you need this flow condition for in the iterator check. Can you expand? (I want to make sure we're not dealing with an XY problem.) |
||||||||
|
||||||||
} // namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to keep code snippets as simple as possible:
Foo
is needed here?initializer_list
is probably the simplest thing you can use to iterate over (it doesn't matter specifically what you're iterating over, right?)