[libcxx-commits] [libcxx] [llvm] [compiler-rt] [clang-tools-extra] [clang] [flang] [libc] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)
Bill Wendling via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 18 14:07:47 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;
+ }
----------------
bwendling wrote:
If you call `getFieldIndex` for a `FieldDecl` that's not in a top-level of the `RecordDecl`, it will assert. So I need to go through each field one at a time, because the method is broken.
I was planning on adding that to the record layout contexts, but because this patch has been through the wringer, I didn't want to throw yet another reason for people to hate it.
https://github.com/llvm/llvm-project/pull/73730
More information about the libcxx-commits
mailing list