aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenModule.cpp
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-06-09 13:11:12 -0700
committerGitHub <noreply@github.com>2025-06-09 13:11:12 -0700
commit6559831025711a21fd1f6a4065c4f3ac53f16875 (patch)
tree1af415800dcb75c9d9fd9f1d9f31f2abef8da623 /clang/lib/CIR/CodeGen/CIRGenModule.cpp
parentf12e4f2faf404a7f44b5505b0a4c14e3a003d2d1 (diff)
downloadllvm-6559831025711a21fd1f6a4065c4f3ac53f16875.zip
llvm-6559831025711a21fd1f6a4065c4f3ac53f16875.tar.gz
llvm-6559831025711a21fd1f6a4065c4f3ac53f16875.tar.bz2
[CIR] Add support for accessing members of base classes (#143195)
This change adds the support for accessing a member of a base class from a derived class object.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index e5eae31..3d46c44 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -19,6 +19,7 @@
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclOpenACC.h"
#include "clang/AST/GlobalDecl.h"
+#include "clang/AST/RecordLayout.h"
#include "clang/Basic/SourceManager.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
@@ -1683,6 +1684,33 @@ bool CIRGenModule::verifyModule() const {
return mlir::verify(theModule).succeeded();
}
+// TODO(cir): this can be shared with LLVM codegen.
+CharUnits CIRGenModule::computeNonVirtualBaseClassOffset(
+ const CXXRecordDecl *derivedClass,
+ llvm::iterator_range<CastExpr::path_const_iterator> path) {
+ CharUnits offset = CharUnits::Zero();
+
+ const ASTContext &astContext = getASTContext();
+ const CXXRecordDecl *rd = derivedClass;
+
+ for (const CXXBaseSpecifier *base : path) {
+ assert(!base->isVirtual() && "Should not see virtual bases here!");
+
+ // Get the layout.
+ const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd);
+
+ const auto *baseDecl = cast<CXXRecordDecl>(
+ base->getType()->castAs<clang::RecordType>()->getDecl());
+
+ // Add the offset.
+ offset += layout.getBaseClassOffset(baseDecl);
+
+ rd = baseDecl;
+ }
+
+ return offset;
+}
+
DiagnosticBuilder CIRGenModule::errorNYI(SourceLocation loc,
llvm::StringRef feature) {
unsigned diagID = diags.getCustomDiagID(