[clang] [clang][dataflow] Refactor `widen` API to be explicit about change effect. (PR #87233)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 2 00:48:07 PDT 2024


================
@@ -975,6 +994,35 @@ TEST_F(WideningTest, DistinctValuesWithSamePropertiesAreEquivalent) {
       });
 }
 
+TEST_F(WideningTest, DistinctValuesWithDifferentPropertiesWidenedToTop) {
+  std::string Code = R"(
+    void target(bool Cond) {
+      int *Foo;
+      int i = 0;
+      Foo = nullptr;
+      while (Cond) {
+        Foo = &i;
+      }
+      (void)0;
+      /*[[p]]*/
+    }
+  )";
+  runDataflow(
+      Code,
+      [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+         ASTContext &ASTCtx) {
+        ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+        const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+        const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+        ASSERT_THAT(FooDecl, NotNull());
+
+        const auto *FooVal = Env.getValue(*FooDecl);
+        EXPECT_TRUE(areEquivalentValues(*FooVal->getProperty("is_null"),
----------------
martinboehme wrote:

I think we also want to test that `getProperty()` returns non-null?

Easiest way might be `*cast<BoolValue>(FooVal->getProperty("is_null"))`. (`cast` asserts that its argument is non-null.)

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


More information about the cfe-commits mailing list