diff --git a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp index 066906c1adc4..740b77915bd1 100644 --- a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp @@ -601,15 +601,16 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *D, builder.lower(/*nonVirtualBaseType=*/false); // If we're in C++, compute the base subobject type. - mlir::cir::StructType *BaseTy = nullptr; + mlir::cir::StructType BaseTy; if (llvm::isa(D) && !D->isUnion() && !D->hasAttr()) { - BaseTy = Ty; + BaseTy = *Ty; if (builder.astRecordLayout.getNonVirtualSize() != builder.astRecordLayout.getSize()) { CIRRecordLowering baseBuilder(*this, D, /*Packed=*/builder.isPacked); + baseBuilder.lower(/*NonVirtualBaseType=*/true); auto baseIdentifier = getRecordTypeName(D, ".base"); - *BaseTy = + BaseTy = Builder.getCompleteStructTy(baseBuilder.fieldTypes, baseIdentifier, /*packed=*/false, D); // TODO(cir): add something like addRecordTypeName @@ -630,7 +631,7 @@ CIRGenTypes::computeRecordLayout(const RecordDecl *D, auto RL = std::make_unique( Ty ? *Ty : mlir::cir::StructType{}, - BaseTy ? *BaseTy : mlir::cir::StructType{}, + BaseTy ? BaseTy : mlir::cir::StructType{}, (bool)builder.IsZeroInitializable, (bool)builder.IsZeroInitializableAsBase); diff --git a/clang/test/CIR/CodeGen/derived-to-base.cpp b/clang/test/CIR/CodeGen/derived-to-base.cpp index 3fa2e245854b..7f0aa10ea573 100644 --- a/clang/test/CIR/CodeGen/derived-to-base.cpp +++ b/clang/test/CIR/CodeGen/derived-to-base.cpp @@ -77,6 +77,9 @@ void C3::Layer::Initialize() { // CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct