[clang] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 5 14:20:53 PST 2023


bwendling wrote:

> I mean, the base case should be "return nullptr", and you should only explicitly list out expressions you know we need to handle. We shouldn't need to explicitly mention VisitUnaryPostDec etc.

The expression can be arbitrarily complex. For instance this:

```
struct s {
  struct s *p;
  int count;
  int array[] __attribute__((count));
};

int foo(struct s *p, int index) {
  return p->p->p->array[index];
}

struct q {
  struct s *ptr[20];
};

int bar(struct q *f, int idx1, int index) {
  return f->ptr[idx1]->p->array[index];
}
```

and so on. If all I was dealing with were `ArraySubscriptExpr(MemberExpr(DeclRefExpr), ArrayIndex)`, I wouldn't have to jump through hoops to deal with these horrors.

In `ArraySubscriptExpr`, I don't even have the luxury of knowing what all of the elements in the expression are, since it could be on an arbitrary recursive level.

https://github.com/llvm/llvm-project/pull/73730


More information about the cfe-commits mailing list