================
@@ -471,13 +474,46 @@ class LifetimeSafetySemaHelperImpl : public
LifetimeSafetySemaHelper {
}
std::string getDiagSubjectDescription(const Expr *E) {
+ // FIXME: Ideally, this should use IgnoreParenImpCasts().
+ // However, according to the comment on IgnoreParenImpCasts(),
+ // it is not fully equivalent to IgnoreImpCasts() + IgnoreParens().
+ // Once the FIXME in IgnoreParenImpCasts() is resolved,
+ // this can be switched to use IgnoreParenImpCasts().
+ E = E->IgnoreImpCasts()->IgnoreParens();
if (isa<MaterializeTemporaryExpr>(E))
return "local temporary object";
if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
return getDiagSubjectDescription(DRE->getDecl());
// TODO: Handle other expression types.
- return "";
+ return "expression";
+ }
+
+ void reportAliasingChain(llvm::ArrayRef<const Expr *> OriginExprChain) {
+ std::string IssueStr;
+ const Expr *IssueExpr = nullptr;
+ const Expr *LastExpr = nullptr;
+
+ for (const Expr *CurrExpr : reverse(OriginExprChain)) {
+ if (!IssueExpr) {
+ IssueStr = getDiagSubjectDescription(CurrExpr);
+ IssueExpr = CurrExpr;
+ LastExpr = CurrExpr;
+ continue;
+ }
----------------
usx95 wrote:
Can we be more explicit here that `IssueExpr` is essentially the first element
here. Something like:
```cpp
if (OriginExprChain.empty())
return;
// IssueExpr is the first element in the chain (last in original order).
// This is the root expression that all subsequent expressions alias.
const Expr *IssueExpr = OriginExprChain.back();
std::string IssueStr = getDiagSubjectDescription(IssueExpr);
const Expr *LastExpr = IssueExpr;
for (const Expr *CurrExpr : reverse(OriginExprChain.drop_back(1))) {
```
https://github.com/llvm/llvm-project/pull/199345
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits