Skip to content

Commit 295489f

Browse files
committed
Address code review comments
1 parent 946f371 commit 295489f

File tree

9 files changed

+44
-26
lines changed

9 files changed

+44
-26
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ CIRGenFunctionInfo::create(CanQualType resultType,
4242
return fi;
4343
}
4444

45-
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
46-
mlir::Type resultType = convertType(fi.getReturnType());
45+
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &info) {
46+
mlir::Type resultType = convertType(info.getReturnType());
4747
SmallVector<mlir::Type, 8> argTypes;
48-
argTypes.reserve(fi.getNumRequiredArgs());
48+
argTypes.reserve(info.getNumRequiredArgs());
4949

50-
for (const CanQualType &argType : fi.requiredArguments())
50+
for (const CanQualType &argType : info.requiredArguments())
5151
argTypes.push_back(convertType(argType));
5252

5353
return cir::FuncType::get(argTypes,
5454
(resultType ? resultType : builder.getVoidTy()),
55-
fi.isVariadic());
55+
info.isVariadic());
5656
}
5757

5858
CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
@@ -269,6 +269,7 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args,
269269
if (type->isRecordType() &&
270270
type->castAs<RecordType>()
271271
->getOriginalDecl()
272+
->getDefinitionOrSelf()
272273
->isParamDestroyedInCallee() &&
273274
param->needsDestruction(getContext())) {
274275
cgm.errorNYI(param->getSourceRange(),
@@ -671,6 +672,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e,
671672
// we make it to the call.
672673
if (argType->isRecordType() && argType->castAs<RecordType>()
673674
->getOriginalDecl()
675+
->getDefinitionOrSelf()
674676
->isParamDestroyedInCallee()) {
675677
assert(!cir::MissingFeatures::msabi());
676678
cgm.errorNYI(e->getSourceRange(), "emitCallArg: msabi is NYI");

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ static void emitMemberInitializer(CIRGenFunction &cgf,
120120

121121
static bool isInitializerOfDynamicClass(const CXXCtorInitializer *baseInit) {
122122
const Type *baseType = baseInit->getBaseClass();
123-
const auto *baseClassDecl =
124-
cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl());
123+
const auto *baseClassDecl = cast<CXXRecordDecl>(baseType->castAs<RecordType>()
124+
->getOriginalDecl()
125+
->getDefinitionOrSelf()
126+
->getDefinitionOrSelf());
125127
return baseClassDecl->isDynamicClass();
126128
}
127129

@@ -160,8 +162,8 @@ void CIRGenFunction::emitBaseInitializer(mlir::Location loc,
160162
Address thisPtr = loadCXXThisAddress();
161163

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

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

@@ -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->getOriginalDecl());
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,8 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
10131013
case CK_DerivedToBase: {
10141014
const auto *derivedClassTy =
10151015
e->getSubExpr()->getType()->castAs<clang::RecordType>();
1016-
auto *derivedClassDecl =
1017-
cast<CXXRecordDecl>(derivedClassTy->getOriginalDecl());
1016+
auto *derivedClassDecl = cast<CXXRecordDecl>(
1017+
derivedClassTy->getOriginalDecl()->getDefinitionOrSelf());
10181018

10191019
LValue lv = emitLValue(e->getSubExpr());
10201020
Address thisAddr = lv.getAddress();
@@ -1168,7 +1168,8 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf,
11681168
->getBaseElementTypeUnsafe()
11691169
->getAs<clang::RecordType>()) {
11701170
// Get the destructor for the reference temporary.
1171-
auto *classDecl = cast<CXXRecordDecl>(rt->getOriginalDecl());
1171+
auto *classDecl =
1172+
cast<CXXRecordDecl>(rt->getOriginalDecl()->getDefinitionOrSelf());
11721173
if (!classDecl->hasTrivialDestructor())
11731174
referenceTemporaryDtor = classDecl->getDestructor();
11741175
}

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>()->getOriginalDecl();
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) {
590590
// assignments and whatnots). Since this is for globals shouldn't
591591
// be a problem for the near future.
592592
if (cd->isTrivial() && cd->isDefaultConstructor()) {
593-
const auto *cxxrd =
594-
cast<CXXRecordDecl>(ty->getAs<RecordType>()->getOriginalDecl());
593+
const auto *cxxrd = cast<CXXRecordDecl>(ty->getAs<RecordType>()
594+
->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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +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 =
360-
dyn_cast<CXXRecordDecl>(recordType->getOriginalDecl()))
359+
if (const auto *classDecl = dyn_cast<CXXRecordDecl>(
360+
recordType->getOriginalDecl()->getDefinitionOrSelf()))
361361
return classDecl->hasTrivialDestructor();
362362
}
363363
return returnType.isTriviallyCopyableType(astContext);
@@ -828,7 +828,8 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
828828
// Ignore empty classes in C++.
829829
if (getLangOpts().CPlusPlus) {
830830
if (const RecordType *rt = ty->getAs<RecordType>()) {
831-
if (cast<CXXRecordDecl>(rt->getOriginalDecl())->isEmpty())
831+
if (cast<CXXRecordDecl>(rt->getOriginalDecl()->getDefinitionOrSelf())
832+
->isEmpty())
832833
return;
833834
}
834835
}

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

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

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt,
139139
if (!alreadyChecked.insert(rd).second)
140140
return true;
141141

142+
assert(rd->isCompleteDefinition() &&
143+
"Expect RecordDecl to be CompleteDefinition");
142144
const Type *key = cgt.getASTContext().getCanonicalTagType(rd).getTypePtr();
143145

144146
// If this type is already laid out, converting it is a noop.
@@ -243,8 +245,10 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) {
243245
for (const auto &base : cxxRecordDecl->bases()) {
244246
if (base.isVirtual())
245247
continue;
246-
convertRecordDeclType(
247-
base.getType()->castAs<RecordType>()->getOriginalDecl());
248+
convertRecordDeclType(base.getType()
249+
->castAs<RecordType>()
250+
->getOriginalDecl()
251+
->getDefinitionOrSelf());
248252
}
249253
}
250254

@@ -277,7 +281,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
277281

278282
// Process record types before the type cache lookup.
279283
if (const auto *recordType = dyn_cast<RecordType>(type))
280-
return convertRecordDeclType(recordType->getOriginalDecl());
284+
return convertRecordDeclType(
285+
recordType->getOriginalDecl()->getDefinitionOrSelf());
281286

282287
// Has the type already been processed?
283288
TypeCacheTy::iterator tci = typeCache.find(ty);

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context,
1010
if (!rt)
1111
return false;
1212

13-
const RecordDecl *rd = rt->getOriginalDecl();
13+
const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf();
1414

1515
// If this is a C++ record, check the bases first.
1616
if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) {

0 commit comments

Comments
 (0)