[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 01:55:16 PDT 2024


================
@@ -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");
+                  ASSERT_TRUE(Env1.proves(Env1.arena().makeAtomRef(Env1.getFlowConditionToken())));
+              });
----------------
martinboehme wrote:

Does this fail without the other changes in this PR?

If it does, this looks to me more like a bug in `DataflowEnvironment`; this assertion should generally be true for _any_ environment, whether or not we extended the flow condition. (In that sense, the name of the test isn't accurate, because we would expect this to pass even if the flow condition was not extended.)

https://github.com/llvm/llvm-project/pull/80989


More information about the cfe-commits mailing list