[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 06:13:22 PDT 2023


================
@@ -324,6 +336,12 @@ getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
   } else if (auto *E = dyn_cast<DeclRefExpr>(&S)) {
     insertIfGlobal(*E->getDecl(), Vars);
     insertIfFunction(*E->getDecl(), Funcs);
+  } else if (const auto *C = dyn_cast<CXXMemberCallExpr>(&S)) {
+    // If this is a method that returns a member variable but does nothing else,
+    // model the field of the return value.
+    if (MemberExpr *E = dyn_cast_or_null<MemberExpr>(
+        getRetValueFromSingleReturnStmtMethod(*C)))
+      getFieldsGlobalsAndFuncs(*E, Fields, Vars, Funcs);
----------------
martinboehme wrote:

```suggestion
      if (const auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()))
        Fields.insert(FD);
```

This is all of the logic that you really need from the recursive `getFieldsGlobalsAndFuncs()` call. I would suggest simply repeating these two lines here:

- The intent is clearer
- You save quite a few unnecessary `dyn_cast`s

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


More information about the cfe-commits mailing list