Skip to content

Commit c9b6242

Browse files
committed
[CIR] Fix build after the improved nested name specifier AST repr (91cdd35)
1 parent d9199a8 commit c9b6242

11 files changed

+69
-44
lines changed

clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static MemberCallInfo commonBuildCXXMemberOrOperatorCall(
7575

7676
RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr(
7777
const CallExpr *ce, const CXXMethodDecl *md, ReturnValueSlot returnValue,
78-
bool hasQualifier, NestedNameSpecifier *qualifier, bool isArrow,
78+
bool hasQualifier, NestedNameSpecifier qualifier, bool isArrow,
7979
const Expr *base) {
8080
assert(isa<CXXMemberCallExpr>(ce) || isa<CXXOperatorCallExpr>(ce));
8181

@@ -169,7 +169,7 @@ CIRGenFunction::emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e,
169169
assert(md->isInstance() &&
170170
"Trying to emit a member call expr on a static method!");
171171
return emitCXXMemberOrOperatorMemberCallExpr(
172-
e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
172+
e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/std::nullopt,
173173
/*IsArrow=*/false, e->getArg(0));
174174
}
175175

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ CIRGenTypes::arrangeCXXStructorDeclaration(GlobalDecl gd) {
203203
/// when calling a method pointer.
204204
CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
205205
const CXXMethodDecl *md) {
206-
QualType recTy;
206+
CanQualType recTy;
207207
if (rd) {
208-
recTy = getASTContext().getTagDeclType(rd)->getCanonicalTypeInternal();
208+
recTy = getASTContext().getCanonicalTagType(rd);
209209
} else {
210210
// This can happen with the MS ABI. It shouldn't need anything more than
211211
// setting recTy to VoidTy here, but we're flagging it for now because we
@@ -215,9 +215,9 @@ CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
215215
}
216216

217217
if (md)
218-
recTy = getASTContext().getAddrSpaceQualType(
219-
recTy, md->getMethodQualifiers().getAddressSpace());
220-
return getASTContext().getPointerType(CanQualType::CreateUnsafe(recTy));
218+
recTy = CanQualType::CreateUnsafe(getASTContext().getAddrSpaceQualType(
219+
recTy, md->getMethodQualifiers().getAddressSpace()));
220+
return getASTContext().getPointerType(recTy);
221221
}
222222

223223
/// Arrange the CIR function layout for a value of the given function type, on
@@ -267,7 +267,10 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args,
267267
// Deactivate the cleanup for the callee-destructed param that was pushed.
268268
assert(!cir::MissingFeatures::thunks());
269269
if (type->isRecordType() &&
270-
type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() &&
270+
type->castAs<RecordType>()
271+
->getOriginalDecl()
272+
->getDefinitionOrSelf()
273+
->isParamDestroyedInCallee() &&
271274
param->needsDestruction(getContext())) {
272275
cgm.errorNYI(param->getSourceRange(),
273276
"emitDelegateCallArg: callee-destructed param");
@@ -667,8 +670,10 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e,
667670
// In the Microsoft C++ ABI, aggregate arguments are destructed by the callee.
668671
// However, we still have to push an EH-only cleanup in case we unwind before
669672
// we make it to the call.
670-
if (argType->isRecordType() &&
671-
argType->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
673+
if (argType->isRecordType() && argType->castAs<RecordType>()
674+
->getOriginalDecl()
675+
->getDefinitionOrSelf()
676+
->isParamDestroyedInCallee()) {
672677
assert(!cir::MissingFeatures::msabi());
673678
cgm.errorNYI(e->getSourceRange(), "emitCallArg: msabi is NYI");
674679
}

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
8686
QualType fieldType = field->getType();
8787

8888
mlir::Value thisPtr = cgf.loadCXXThis();
89-
QualType recordTy = cgf.getContext().getTypeDeclType(classDecl);
89+
CanQualType recordTy = cgf.getContext().getCanonicalTagType(classDecl);
9090

9191
// If a base constructor is being emitted, create an LValue that has the
9292
// non-virtual alignment.
@@ -121,7 +121,8 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
121121
static bool isInitializerOfDynamicClass(const CXXCtorInitializer *baseInit) {
122122
const Type *baseType = baseInit->getBaseClass();
123123
const auto *baseClassDecl =
124-
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl());
124+
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl())
125+
->getDefinitionOrSelf();
125126
return baseClassDecl->isDynamicClass();
126127
}
127128

@@ -161,7 +162,8 @@ void CIRGenFunction::emitBaseInitializer(mlir::Location loc,
161162

162163
const Type *baseType = baseInit->getBaseClass();
163164
const auto *baseClassDecl =
164-
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl());
165+
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl())
166+
->getDefinitionOrSelf();
165167

166168
bool isBaseVirtual = baseInit->isBaseVirtual();
167169

@@ -377,7 +379,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
377379
//
378380
// Note that these are complete objects and so we don't need to
379381
// use the non-virtual size or alignment.
380-
QualType type = getContext().getTypeDeclType(ctor->getParent());
382+
CanQualType type = getContext().getCanonicalTagType(ctor->getParent());
381383
CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement(
382384
getContext().getTypeSizeInChars(type));
383385

@@ -484,7 +486,8 @@ void CIRGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &args) {
484486
void CIRGenFunction::destroyCXXObject(CIRGenFunction &cgf, Address addr,
485487
QualType type) {
486488
const RecordType *rtype = type->castAs<RecordType>();
487-
const CXXRecordDecl *record = cast<CXXRecordDecl>(rtype->getDecl());
489+
const CXXRecordDecl *record =
490+
cast<CXXRecordDecl>(rtype->getOriginalDecl())->getDefinitionOrSelf();
488491
const CXXDestructorDecl *dtor = record->getDestructor();
489492
// TODO(cir): Unlike traditional codegen, CIRGen should actually emit trivial
490493
// dtors which shall be removed on later CIR passes. However, only remove this

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,9 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
10131013
case CK_DerivedToBase: {
10141014
const auto *derivedClassTy =
10151015
e->getSubExpr()->getType()->castAs<clang::RecordType>();
1016-
auto *derivedClassDecl = cast<CXXRecordDecl>(derivedClassTy->getDecl());
1016+
auto *derivedClassDecl =
1017+
cast<CXXRecordDecl>(derivedClassTy->getOriginalDecl())
1018+
->getDefinitionOrSelf();
10171019

10181020
LValue lv = emitLValue(e->getSubExpr());
10191021
Address thisAddr = lv.getAddress();
@@ -1167,9 +1169,10 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf,
11671169
->getBaseElementTypeUnsafe()
11681170
->getAs<clang::RecordType>()) {
11691171
// Get the destructor for the reference temporary.
1170-
auto *classDecl = cast<CXXRecordDecl>(rt->getDecl());
1172+
auto *classDecl = cast<CXXRecordDecl>(rt->getOriginalDecl());
11711173
if (!classDecl->hasTrivialDestructor())
1172-
referenceTemporaryDtor = classDecl->getDestructor();
1174+
referenceTemporaryDtor =
1175+
classDecl->getDefinitionOrSelf()->getDestructor();
11731176
}
11741177

11751178
if (!referenceTemporaryDtor)
@@ -1831,7 +1834,7 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce,
18311834
}
18321835

18331836
bool hasQualifier = me->hasQualifier();
1834-
NestedNameSpecifier *qualifier = hasQualifier ? me->getQualifier() : nullptr;
1837+
NestedNameSpecifier qualifier = me->getQualifier();
18351838
bool isArrow = me->isArrow();
18361839
const Expr *base = me->getBase();
18371840

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
376376
// the disadvantage is that the generated code is more difficult for
377377
// the optimizer, especially with bitfields.
378378
unsigned numInitElements = args.size();
379-
RecordDecl *record = e->getType()->castAs<RecordType>()->getDecl();
379+
RecordDecl *record = e->getType()
380+
->castAs<RecordType>()
381+
->getOriginalDecl()
382+
->getDefinitionOrSelf();
380383

381384
// We'll need to enter cleanup scopes in case any of the element
382385
// initializers throws an exception.

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) {
591591
// be a problem for the near future.
592592
if (cd->isTrivial() && cd->isDefaultConstructor()) {
593593
const auto *cxxrd =
594-
cast<CXXRecordDecl>(ty->getAs<RecordType>()->getDecl());
594+
cast<CXXRecordDecl>(ty->getAs<RecordType>()->getOriginalDecl())
595+
->getDefinitionOrSelf();
595596
if (cxxrd->getNumBases() != 0) {
596597
// There may not be anything additional to do here, but this will
597598
// force us to pause and test this path when it is supported.

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ static bool mayDropFunctionReturn(const ASTContext &astContext,
356356
// destructor or a non-trivially copyable type.
357357
if (const RecordType *recordType =
358358
returnType.getCanonicalType()->getAs<RecordType>()) {
359-
if (const auto *classDecl = dyn_cast<CXXRecordDecl>(recordType->getDecl()))
359+
if (const auto *classDecl =
360+
dyn_cast<CXXRecordDecl>(recordType->getOriginalDecl()))
360361
return classDecl->hasTrivialDestructor();
361362
}
362363
return returnType.isTriviallyCopyableType(astContext);
@@ -827,7 +828,9 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
827828
// Ignore empty classes in C++.
828829
if (getLangOpts().CPlusPlus) {
829830
if (const RecordType *rt = ty->getAs<RecordType>()) {
830-
if (cast<CXXRecordDecl>(rt->getDecl())->isEmpty())
831+
if (cast<CXXRecordDecl>(rt->getOriginalDecl())
832+
->getDefinitionOrSelf()
833+
->isEmpty())
831834
return;
832835
}
833836
}
@@ -978,10 +981,6 @@ void CIRGenFunction::emitVariablyModifiedType(QualType type) {
978981
case Type::BitInt:
979982
llvm_unreachable("type class is never variably-modified!");
980983

981-
case Type::Elaborated:
982-
type = cast<clang::ElaboratedType>(ty)->getNamedType();
983-
break;
984-
985984
case Type::Adjusted:
986985
type = cast<clang::AdjustedType>(ty)->getAdjustedType();
987986
break;

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class CIRGenFunction : public CIRGenTypeCache {
10111011
RValue emitCXXMemberOrOperatorMemberCallExpr(
10121012
const clang::CallExpr *ce, const clang::CXXMethodDecl *md,
10131013
ReturnValueSlot returnValue, bool hasQualifier,
1014-
clang::NestedNameSpecifier *qualifier, bool isArrow,
1014+
clang::NestedNameSpecifier qualifier, bool isArrow,
10151015
const clang::Expr *base);
10161016

10171017
mlir::Value emitCXXNewExpr(const CXXNewExpr *e);

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static bool isVarDeclStrongDefinition(const ASTContext &astContext,
997997
return true;
998998

999999
if (const auto *rt = varType->getAs<RecordType>()) {
1000-
const RecordDecl *rd = rt->getDecl();
1000+
const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf();
10011001
for (const FieldDecl *fd : rd->fields()) {
10021002
if (fd->isBitField())
10031003
continue;
@@ -2066,8 +2066,10 @@ CharUnits CIRGenModule::computeNonVirtualBaseClassOffset(
20662066
// Get the layout.
20672067
const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd);
20682068

2069-
const auto *baseDecl = cast<CXXRecordDecl>(
2070-
base->getType()->castAs<clang::RecordType>()->getDecl());
2069+
const auto *baseDecl =
2070+
cast<CXXRecordDecl>(
2071+
base->getType()->castAs<clang::RecordType>()->getOriginalDecl())
2072+
->getDefinitionOrSelf();
20712073

20722074
// Add the offset.
20732075
offset += layout.getBaseClassOffset(baseDecl);

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl,
103103
policy.SuppressTagKeyword = true;
104104

105105
if (recordDecl->getIdentifier())
106-
astContext.getRecordType(recordDecl).print(outStream, policy);
106+
QualType(astContext.getCanonicalTagType(recordDecl))
107+
.print(outStream, policy);
107108
else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl())
108109
typedefNameDecl->printQualifiedName(outStream, policy);
109110
else
@@ -138,7 +139,7 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt,
138139
if (!alreadyChecked.insert(rd).second)
139140
return true;
140141

141-
const Type *key = cgt.getASTContext().getTagDeclType(rd).getTypePtr();
142+
const Type *key = cgt.getASTContext().getCanonicalTagType(rd).getTypePtr();
142143

143144
// If this type is already laid out, converting it is a noop.
144145
if (cgt.isRecordLayoutComplete(key))
@@ -182,7 +183,8 @@ isSafeToConvert(QualType qt, CIRGenTypes &cgt,
182183

183184
// If this is a record, check it.
184185
if (const auto *rt = qt->getAs<RecordType>())
185-
return isSafeToConvert(rt->getDecl(), cgt, alreadyChecked);
186+
return isSafeToConvert(rt->getOriginalDecl()->getDefinitionOrSelf(), cgt,
187+
alreadyChecked);
186188

187189
// If this is an array, check the elements, which are embedded inline.
188190
if (const auto *at = cgt.getASTContext().getAsArrayType(qt))
@@ -210,7 +212,7 @@ static bool isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt) {
210212
mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
211213
// TagDecl's are not necessarily unique, instead use the (clang) type
212214
// connected to the decl.
213-
const Type *key = astContext.getTagDeclType(rd).getTypePtr();
215+
const Type *key = astContext.getCanonicalTagType(rd).getTypePtr();
214216
cir::RecordType entry = recordDeclTypes[key];
215217

216218
// If we don't have an entry for this record yet, create one.
@@ -242,7 +244,10 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
242244
for (const auto &base : cxxRecordDecl->bases()) {
243245
if (base.isVirtual())
244246
continue;
245-
convertRecordDeclType(base.getType()->castAs<RecordType>()->getDecl());
247+
convertRecordDeclType(base.getType()
248+
->castAs<RecordType>()
249+
->getOriginalDecl()
250+
->getDefinitionOrSelf());
246251
}
247252
}
248253

@@ -275,7 +280,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
275280

276281
// Process record types before the type cache lookup.
277282
if (const auto *recordType = dyn_cast<RecordType>(type))
278-
return convertRecordDeclType(recordType->getDecl());
283+
return convertRecordDeclType(
284+
recordType->getOriginalDecl()->getDefinitionOrSelf());
279285

280286
// Has the type already been processed?
281287
TypeCacheTy::iterator tci = typeCache.find(ty);
@@ -457,7 +463,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
457463
}
458464

459465
case Type::Enum: {
460-
const EnumDecl *ed = cast<EnumType>(ty)->getDecl();
466+
const EnumDecl *ed =
467+
cast<EnumType>(ty)->getOriginalDecl()->getDefinitionOrSelf();
461468
if (auto integerType = ed->getIntegerType(); !integerType.isNull())
462469
return convertType(integerType);
463470
// Return a placeholder 'i32' type. This can be changed later when the
@@ -516,7 +523,7 @@ mlir::Type CIRGenTypes::convertTypeForMem(clang::QualType qualType,
516523
/// Return record layout info for the given record decl.
517524
const CIRGenRecordLayout &
518525
CIRGenTypes::getCIRGenRecordLayout(const RecordDecl *rd) {
519-
const auto *key = astContext.getTagDeclType(rd).getTypePtr();
526+
const auto *key = astContext.getCanonicalTagType(rd).getTypePtr();
520527

521528
// If we have already computed the layout, return it.
522529
auto it = cirGenRecordLayouts.find(key);
@@ -548,7 +555,7 @@ bool CIRGenTypes::isZeroInitializable(clang::QualType t) {
548555
}
549556

550557
if (const RecordType *rt = t->getAs<RecordType>()) {
551-
const RecordDecl *rd = rt->getDecl();
558+
const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf();
552559
return isZeroInitializable(rd);
553560
}
554561

@@ -623,8 +630,10 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) {
623630
// declaration of enums, and C doesn't allow an incomplete forward
624631
// declaration with a non-default type.
625632
assert(
626-
!typeCache.count(ed->getTypeForDecl()) ||
627-
(convertType(ed->getIntegerType()) == typeCache[ed->getTypeForDecl()]));
633+
!typeCache.count(
634+
ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()) ||
635+
(convertType(ed->getIntegerType()) ==
636+
typeCache[ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()]));
628637
// If necessary, provide the full definition of a type only used with a
629638
// declaration so far.
630639
assert(!cir::MissingFeatures::generateDebugInfo());
@@ -639,7 +648,7 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) {
639648

640649
// Only complete if we converted it already. If we haven't converted it yet,
641650
// we'll just do it lazily.
642-
if (recordDeclTypes.count(astContext.getTagDeclType(rd).getTypePtr()))
651+
if (recordDeclTypes.count(astContext.getCanonicalTagType(rd).getTypePtr()))
643652
convertRecordDeclType(rd);
644653

645654
// If necessary, provide the full definition of a type only used with a

0 commit comments

Comments
 (0)