[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 15 23:48:39 PDT 2023
================
@@ -913,6 +913,34 @@ TEST_F(FlowConditionTest, WhileStmt) {
});
}
+TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) {
+ std::string Code = R"(
+ void target(bool Foo) {
+ // This test checks whether the analysis preserves the connection between
+ // the value of `Foo` and the assignment expression, despite widening.
+ // The equality operator generates a fresh boolean variable on each
+ // interpretation, which forces use of widening.
+ while ((Foo = (3 == 4))) {
+ (void)0;
+ /*[[p]]*/
+ }
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
----------------
martinboehme wrote:
Suggest deleting this assertion. `getEnvironmentAtAnnotation()` already asserts that an annotation "p" exists.
(I know we assert this in a lot of existing tests, but it just seems like clutter.)
https://github.com/llvm/llvm-project/pull/68923
More information about the cfe-commits
mailing list