From 89525cbf283f1ffeca1e007a06b29917a9eadc53 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Fri, 25 Mar 2022 15:39:43 -0400 Subject: [PATCH] [Clang] Add helper method to determine if a nonvirtual base has an entry in the LLVM struct This patch adds a helper method to determine if a nonvirtual base has an entry in the LLVM struct. Such a base may not have an entry if the base does not have any fields/bases itself that would change the size of the struct. This utility method is useful for other frontends (Polygeist) that use Clang as an API to generate code. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D122502 --- clang/lib/CodeGen/CGRecordLayout.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clang/lib/CodeGen/CGRecordLayout.h b/clang/lib/CodeGen/CGRecordLayout.h index 5a3bcdf72f7b..d5ea74922603 100644 --- a/clang/lib/CodeGen/CGRecordLayout.h +++ b/clang/lib/CodeGen/CGRecordLayout.h @@ -200,6 +200,12 @@ public: return FieldInfo.lookup(FD); } + // Return whether the following non virtual base has a corresponding + // entry in the LLVM struct. + bool hasNonVirtualBaseLLVMField(const CXXRecordDecl *RD) const { + return NonVirtualBases.count(RD); + } + unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const { assert(NonVirtualBases.count(RD) && "Invalid non-virtual base!"); return NonVirtualBases.lookup(RD);