[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
================
@@ -288,6 +288,18 @@ static void insertIfFunction(const Decl &D,
Funcs.insert(FD);
}
+static Expr *getRetValueFromSingleReturnStmtMethod(const CXXMemberCallExpr &C) {
+ auto *D = cast_or_null<CXXMethodDecl>(C.getMethodDecl()->getDefinition());
+ if (!D)
+ return nullptr;
+ auto *S = cast<CompoundStmt>(D->getBody());
+ if (S->size() != 1)
+ return nullptr;
+ if (auto *RS = dyn_cast<ReturnStmt>(*S->body_begin()))
+ return RS->getRetValue()->IgnoreParenImpCasts();
+ return nullptr;
----------------
martinboehme wrote:
```suggestion
auto *Body = dyn_cast<CompoundStmt>(C.getBody());
if (!Body || Body->size() != 1)
return nullptr;
if (auto *RS = dyn_cast<ReturnStmt>(*Body->body_begin()))
return RS->getRetValue()->IgnoreParenImpCasts();
return nullptr;
```
- `getBody()` can be called on any declaration, not just the definition
- Suggest renaming `S` to `Body` for clarity
- The fact that `getBody()` returns just a `Stmt *` makes me wary that casting unconditionally to `CompoundStmt` may not be safe, so suggest using `dyn_cast` instead.
https://github.com/llvm/llvm-project/pull/66368
More information about the cfe-commits
mailing list