[clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 29 15:27:37 PST 2023
================
@@ -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
More information about the cfe-commits
mailing list