[clang] [clang][dataflow] Disallow setting properties on `RecordValue`s. (PR #76042)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 21 11:00:07 PST 2023


================
@@ -636,40 +636,37 @@ class OptionalIntAnalysis final
     if (!CS)
       return;
     const Stmt *S = CS->getStmt();
-    auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
-    auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
-
-    SmallVector<BoundNodes, 1> Matches = match(
-        stmt(anyOf(cxxConstructExpr(HasOptionalIntType).bind("construct"),
-                   cxxOperatorCallExpr(
-                       callee(cxxMethodDecl(ofClass(OptionalIntRecordDecl))))
-                       .bind("operator"))),
-        *S, getASTContext());
-    if (const auto *E = selectFirst<CXXConstructExpr>(
-            "construct", Matches)) {
-      cast<RecordValue>(Env.getValue(*E))
-          ->setProperty("has_value", Env.getBoolLiteralValue(false));
-    } else if (const auto *E =
-                   selectFirst<CXXOperatorCallExpr>("operator", Matches)) {
-      assert(E->getNumArgs() > 0);
-      auto *Object = E->getArg(0);
-      assert(Object != nullptr);
-
-      refreshRecordValue(*Object, Env)
-          .setProperty("has_value", Env.getBoolLiteralValue(true));
+    const Expr *E = dyn_cast<Expr>(S);
+    if (!E)
+      return;
+
+    if (!E->getType()->isPointerType())
+      return;
+
+    // Make sure we have a `PointerValue` for `E`.
+    auto *PtrVal = cast_or_null<PointerValue>(Env.getValue(*E));
----------------
Xazax-hun wrote:

I think the reason why it might be worth spending some time thinking about convergence because this is probably one of the bigger challenges for people writing checks. The other reason why this might be an interesting question, because in case we want to run multiple checks in the same fixed-point iteration, we might not want arbitrary interactions between them. 

That being said, there are many moving pieces that we have not figured yet out, so I 100% agree that it might be too early to try to solve this problem now. 

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


More information about the cfe-commits mailing list