[clang] [LifetimeSafety] Add multi-block support to buildOriginFlowChain (PR #204592)
Yuan Suo via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 21 00:13:23 PDT 2026
================
@@ -534,11 +534,24 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
return "expression";
}
+ bool isInValidExpr(const Expr *E) {
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
+ return DRE->getDecl()->isImplicit();
+ }
+
+ if (const auto *CE = dyn_cast<CallExpr>(E)) {
+ if (const auto *FE = CE->getDirectCallee())
+ return FE->isImplicit();
+ }
----------------
suoyuan666 wrote:
Yeah, that makes sense. I have added a fallback that `returns false` when `CallExpr->getDirectCallee()` is `nullptr`.
If our goal is simply to avoid printing internal variable names, I think that should be sufficient, since `getDiagSubjectDescription()` only prints the callee name when the `FunctionDecl` is available.
As for a test case where a function pointer appears on the RHS, I don't have much experience with that yet, so I wasn't able to come up with one that actually triggers the warning. The following example doesn't seem to work:
```cpp
void foo() {
int *s;
{
int *(*func)(int *);
int tgt = 2;
int *a = &tgt;
s = func(a);
}
(void)*s;
}
```
https://github.com/llvm/llvm-project/pull/204592
More information about the cfe-commits
mailing list