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

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 12:34:09 PST 2023


bwendling wrote:

> CodeGenFunction::FindCountedByField finds a field with a corresponding base expression. Currently, it throws away the base expression. And the code you've just written tries to recompute the base. Instead of doing this dance, can we just make CodeGenFunction::FindCountedByField return both the field and the base expression?

Maybe... `CodeGenFunction::FindCountedByField` isn't super concerned with finding the `DeclRefExpr`. It just goes down the `RecordDecl` to find the `Decl` with the `counted_by` attribute. It jumps through some hoops to see if the FAM is in a sub-structure. I'll look into it though.

> I'm extremely suspicious of the way MemberExprBaseVisitor works; it's basically never right in CodeGen to treat all CastExprs the same way, or handle MemberExprs without checking isArrow().

I initially had a check to see if a cast had the same `RecordDecl` type as the one we're looking for; if so return that expression. Would that help in this case? I'm also wondering about the `ParenExpr`. Should they get the same treatment?

For the `MemberExprs`, I could check the `isArrow()`, but in that case we'd be dealing with a pointer into another object, which ... ick. We should probably return `nullptr` in that instance. At this point though, we *should* be dealing with a more-or-less well structured `MemberExpr` to `DeclRefExpr` expression. I.e. it'll be a list of `MemberExprs` with potential casts and maybe a `UnaryOperand` thrown in for good measure until we get to a `DeclRefExpr` or `CompoundLiteralExpr`. Of course, it's hard to state anything for sure with C, but I'll need examples to help harden this code.

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


More information about the cfe-commits mailing list