[libcxx-commits] [flang] [libcxx] [clang] [compiler-rt] [clang-tools-extra] [libc] [llvm] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
John McCall via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 18 14:30:56 PST 2023
================
@@ -3946,6 +4080,32 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
return Address(eltPtr, CGF.ConvertTypeForMem(eltType), eltAlign);
}
+static bool GetFieldOffsetInBits(CodeGenFunction &CGF, const RecordDecl *RD,
+ const FieldDecl *FD, uint64_t &Offset) {
+ ASTContext &Ctx = CGF.getContext();
+ const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+ unsigned FieldNo = 0;
+
+ for (const Decl *D : RD->decls()) {
+ if (const auto *Record = dyn_cast<RecordDecl>(D))
+ if (GetFieldOffsetInBits(CGF, Record, FD, Offset)) {
+ Offset += Layout.getFieldOffset(FieldNo);
+ return true;
+ }
+
+ if (const auto *Field = dyn_cast<FieldDecl>(D))
+ if (FD == Field) {
+ Offset += Layout.getFieldOffset(FieldNo);
+ return true;
+ }
+
+ if (isa<FieldDecl>(D))
+ ++FieldNo;
+ }
----------------
rjmccall wrote:
Let's start by breaking that out as a separate patch. Just make a method on `ASTRecordLayout` that takes an `IndirectFieldDecl` and recursively adds up the offsets for every step in the path.
https://github.com/llvm/llvm-project/pull/73730
More information about the libcxx-commits
mailing list