bwendling wrote: The problem we're faced with here is that the `Base` pointer could point to anywhere within the structure. We already jump through several hoops to get the flexible array member's `Decl` and the counter's `Decl`.
So because `Base` could be a pointer to anywhere in the struct, we have to determine *where* it's pointing. If it's a pointer to the beginning of the struct (i.e. `__builtin_dynamic_object_size(ptr, 0)`), then we expect a `DeclRefExpr` from the visitor. But we could have something like this: ```c struct s { struct s *p; /* ... */ } *ptr; __builtin_dynamic_object_size(ptr->p->p->p->p, 0); ``` That's caught as a `MemberExpr`. We can have the `__bdos` pointing somewhere within the flexible array member. Etc., etc. Notice that we can't rely upon looking at a `CastExpr's` type to determine exactly what we're looking at. What this code is therefore *trying* to do is simply find a starting point (some `Expr`) from which to build a GEP to the `counted_by` field. It does that in part by using the `CountDecl's` outer lexical record context to stop when we've found the correct base (note that the counted_by's outer lexical record context has already been checked to be the same as the flexible array member's outer lexical record context). I'm not sure what you mean by "or it finds a pointer that's the base". The `MemberExpr` the visitor returns doesn't have to be a pointer---e.g. `ptr->a.b.c.d` returning `ptr->a.b`, where `b` isn't a pointer---or do you mean something else? https://github.com/llvm/llvm-project/pull/110497 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits