================ @@ -956,42 +958,112 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, return nullptr; } -const Expr * -CodeGenFunction::BuildCountedByFieldExpr(const Expr *Base, - const ValueDecl *CountedByVD) { +namespace { + +/// \p MemberExprBaseVisitor returns the base \p DeclRefExpr of a field access. +class MemberExprBaseVisitor + : public StmtVisitor<MemberExprBaseVisitor, Expr *> { + const RecordDecl *ExpectedRD; + + bool IsExpectedRecordDecl(const Expr *E) const { + QualType Ty = E->getType(); + if (Ty->isPointerType()) + Ty = Ty->getPointeeType(); + return ExpectedRD == Ty->getAsRecordDecl(); + } + +public: + MemberExprBaseVisitor(const RecordDecl *ExpectedRD) + : ExpectedRD(ExpectedRD) { } + + //===--------------------------------------------------------------------===// + // Visitor Methods + //===--------------------------------------------------------------------===// + + // Note: if we build C++ support for counted_by, then we'll have to handle + // horrors like this: + // + // struct S { + // int x, y; + // int blah[] __attribute__((counted_by(x))); + // } s; + // + // int foo(int index, int val) { + // int (S::*IHatePMDs)[] = &S::blah; + // (s.*IHatePMDs)[index] = val; + // } + + Expr *Visit(Expr *E) { + return StmtVisitor<MemberExprBaseVisitor, Expr *>::Visit(E); + } + + Expr *VisitCastExpr(CastExpr *E) { ---------------- efriedma-quic wrote:
Did you mean to have codepaths for both CastExpr and ImplicitCastExpr? https://github.com/llvm/llvm-project/pull/73730 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits