================
@@ -480,6 +485,54 @@ class LifetimeSafetySemaHelperImpl : public
LifetimeSafetySemaHelper {
return "";
}
+ const Expr *extractExpr(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().
+ const Expr *PureExpr = E->IgnoreImpCasts()->IgnoreParens();
+
+ if (const auto *UO = dyn_cast<UnaryOperator>(PureExpr))
+ return UO->getSubExpr();
+ // For a BinaryOperator, there is only one relevant case: assignment
+ // chains. Therefore, we only need to consider the LHS expression.
+ if (const auto *BO = dyn_cast<BinaryOperator>(PureExpr))
+ return BO->getLHS();
+
+ // TODO: Handle other expression types.
+ return PureExpr;
+ }
+
+ void reportAliasingChain(llvm::ArrayRef<const Expr *> OriginExprChain) {
+ std::string IssueStr;
+ const Expr *LastExpr = nullptr;
+ for (const Expr *CurrExpr : reverse(OriginExprChain)) {
+ if (IssueStr.empty()) {
+ IssueStr = getDiagSubjectDescription(CurrExpr);
+ LastExpr = CurrExpr;
+ continue;
+ }
+
+ const Expr *ExtractedExpr = extractExpr(CurrExpr);
+ if (LastExpr &&
----------------
NeKon69 wrote:
Isn't `LastExpr` always going to be something here?
https://github.com/llvm/llvm-project/pull/199345
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits