================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits