Skip to content

Commit a859f31

Browse files
authored
[CIR][NFC] Fix warnings after rebasing with the upstream (#1985)
Fix warnings after rebasing with the upstream - Deprecation warnings. - Missing enum elements to make a switch statement complete. - Use Op::create.
1 parent cb1db52 commit a859f31

19 files changed

+176
-193
lines changed

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ bool CIRGenModule::tryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
7777
continue;
7878

7979
// Skip base classes with trivial destructors.
80-
const auto *Base =
81-
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
80+
const auto *Base = I.getType()->getAsCXXRecordDecl();
8281
if (Base->hasTrivialDestructor())
8382
continue;
8483

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const Expr *E,
790790
// However, we still have to push an EH-only cleanup in case we unwind before
791791
// we make it to the call.
792792
if (type->isRecordType() &&
793-
type->castAs<RecordType>()->getOriginalDecl()->isParamDestroyedInCallee()) {
793+
type->getAsRecordDecl()->isParamDestroyedInCallee()) {
794794
llvm_unreachable("Microsoft C++ ABI is NYI");
795795
}
796796

@@ -1105,10 +1105,9 @@ const CIRGenFunctionInfo &
11051105
CIRGenTypes::arrangeFreeFunctionType(CanQual<FunctionNoProtoType> FTNP) {
11061106
// When translating an unprototyped function type, always use a
11071107
// variadic type.
1108-
return arrangeCIRFunctionInfo(FTNP->getReturnType().getUnqualifiedType(),
1109-
cir::FnInfoOpts::None,
1110-
llvm::ArrayRef<CanQualType>{},
1111-
FTNP->getExtInfo(), {}, RequiredArgs(0));
1108+
return arrangeCIRFunctionInfo(
1109+
FTNP->getReturnType().getUnqualifiedType(), cir::FnInfoOpts::None,
1110+
llvm::ArrayRef<CanQualType>{}, FTNP->getExtInfo(), {}, RequiredArgs(0));
11121111
}
11131112

11141113
const CIRGenFunctionInfo &
@@ -1218,7 +1217,7 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args,
12181217

12191218
// Deactivate the cleanup for the callee-destructed param that was pushed.
12201219
if (type->isRecordType() && !CurFuncIsThunk &&
1221-
type->castAs<RecordType>()->getOriginalDecl()->isParamDestroyedInCallee() &&
1220+
type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() &&
12221221
param->needsDestruction(getContext())) {
12231222
llvm_unreachable("NYI");
12241223
}

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class FieldMemcpyizer {
162162

163163
CharUnits memcpySize = getMemcpySize(firstByteOffset);
164164
QualType recordTy = CGF.getContext().getTagType(
165-
ElaboratedTypeKeyword::None, /*Qualifier=*/std::nullopt,
166-
ClassDecl, /*OwnsTag=*/false);
165+
ElaboratedTypeKeyword::None, /*Qualifier=*/std::nullopt, ClassDecl,
166+
/*OwnsTag=*/false);
167167
Address thisPtr = CGF.LoadCXXThisAddress();
168168
LValue destLv = CGF.makeAddrLValue(thisPtr, recordTy);
169169
LValue dest = CGF.emitLValueForFieldInitialization(destLv, FirstField,
@@ -521,8 +521,7 @@ class AssignmentMemcpyizer : public FieldMemcpyizer {
521521

522522
static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit) {
523523
const Type *BaseType = BaseInit->getBaseClass();
524-
const auto *BaseClassDecl =
525-
cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getOriginalDecl());
524+
const auto *BaseClassDecl = BaseType->castAsCXXRecordDecl();
526525
return BaseClassDecl->isDynamicClass();
527526
}
528527

@@ -608,8 +607,7 @@ static void emitBaseInitializer(mlir::Location loc, CIRGenFunction &CGF,
608607
Address ThisPtr = CGF.LoadCXXThisAddress();
609608

610609
const Type *BaseType = BaseInit->getBaseClass();
611-
const auto *BaseClassDecl =
612-
cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getOriginalDecl());
610+
const auto *BaseClassDecl = BaseType->getAsCXXRecordDecl();
613611

614612
bool isBaseVirtual = BaseInit->isBaseVirtual();
615613

@@ -871,8 +869,7 @@ void CIRGenFunction::getVTablePointers(BaseSubobject Base,
871869

872870
// Traverse bases.
873871
for (const auto &I : RD->bases()) {
874-
auto *BaseDecl =
875-
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
872+
auto *BaseDecl = I.getType()->getAsCXXRecordDecl();
876873

877874
// Ignore classes without a vtable.
878875
if (!BaseDecl->isDynamicClass())
@@ -1088,7 +1085,7 @@ void CIRGenFunction::emitLambdaStaticInvokeBody(const CXXMethodDecl *MD) {
10881085
void CIRGenFunction::destroyCXXObject(CIRGenFunction &CGF, Address addr,
10891086
QualType type) {
10901087
const RecordType *rtype = type->castAs<RecordType>();
1091-
const CXXRecordDecl *record = cast<CXXRecordDecl>(rtype->getOriginalDecl());
1088+
const CXXRecordDecl *record = rtype->getAsCXXRecordDecl();
10921089
const CXXDestructorDecl *dtor = record->getDestructor();
10931090
// TODO(cir): Unlike traditional codegen, CIRGen should actually emit trivial
10941091
// dtors which shall be removed on later CIR passes. However, only remove this
@@ -1123,8 +1120,7 @@ HasTrivialDestructorBody(ASTContext &astContext,
11231120
if (I.isVirtual())
11241121
continue;
11251122

1126-
const CXXRecordDecl *NonVirtualBase =
1127-
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
1123+
const CXXRecordDecl *NonVirtualBase = I.getType()->getAsCXXRecordDecl();
11281124
if (!HasTrivialDestructorBody(astContext, NonVirtualBase,
11291125
MostDerivedClassDecl))
11301126
return false;
@@ -1133,8 +1129,7 @@ HasTrivialDestructorBody(ASTContext &astContext,
11331129
if (BaseClassDecl == MostDerivedClassDecl) {
11341130
// Check virtual bases.
11351131
for (const auto &I : BaseClassDecl->vbases()) {
1136-
const CXXRecordDecl *VirtualBase =
1137-
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
1132+
const CXXRecordDecl *VirtualBase = I.getType()->getAsCXXRecordDecl();
11381133
if (!HasTrivialDestructorBody(astContext, VirtualBase,
11391134
MostDerivedClassDecl))
11401135
return false;
@@ -1154,7 +1149,7 @@ static bool FieldHasTrivialDestructorBody(ASTContext &astContext,
11541149
if (!RT)
11551150
return true;
11561151

1157-
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getOriginalDecl());
1152+
CXXRecordDecl *FieldClassDecl = RT->getAsCXXRecordDecl();
11581153

11591154
// The destructor for an implicit anonymous union member is never invoked.
11601155
if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
@@ -1247,6 +1242,8 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &Args) {
12471242
// we'd introduce *two* handler blocks. In the Microsoft ABI, we
12481243
// always delegate because we might not have a definition in this TU.
12491244
switch (DtorType) {
1245+
case Dtor_Unified:
1246+
llvm_unreachable("not expecting a unified dtor");
12501247
case Dtor_Comdat:
12511248
llvm_unreachable("not expecting a COMDAT");
12521249
case Dtor_Deleting:
@@ -1405,8 +1402,7 @@ void CIRGenFunction::EnterDtorCleanups(const CXXDestructorDecl *DD,
14051402
// We push them in the forward order so that they'll be popped in
14061403
// the reverse order.
14071404
for (const auto &Base : ClassDecl->vbases()) {
1408-
auto *BaseClassDecl =
1409-
cast<CXXRecordDecl>(Base.getType()->castAs<RecordType>()->getOriginalDecl());
1405+
auto *BaseClassDecl = Base.getType()->getAsCXXRecordDecl();
14101406

14111407
if (BaseClassDecl->hasTrivialDestructor()) {
14121408
// Under SanitizeMemoryUseAfterDtor, poison the trivial base class
@@ -1466,7 +1462,7 @@ void CIRGenFunction::EnterDtorCleanups(const CXXDestructorDecl *DD,
14661462

14671463
// Anonymous union members do not have their destructors called.
14681464
const RecordType *RT = type->getAsUnionType();
1469-
if (RT && RT->getOriginalDecl()->isAnonymousStructOrUnion())
1465+
if (RT && RT->getDecl()->isAnonymousStructOrUnion())
14701466
continue;
14711467

14721468
CleanupKind cleanupKind = getCleanupKind(dtorKind);
@@ -1593,8 +1589,7 @@ Address CIRGenFunction::getAddressOfDerivedClass(
15931589
CastExpr::path_const_iterator pathEnd, bool nullCheckValue) {
15941590
assert(pathBegin != pathEnd && "Base path should not be empty!");
15951591

1596-
QualType derivedTy =
1597-
getContext().getCanonicalTagType(derived);
1592+
QualType derivedTy = getContext().getCanonicalTagType(derived);
15981593
mlir::Type derivedValueTy = convertType(derivedTy);
15991594
CharUnits nonVirtualOffset =
16001595
CGM.getNonVirtualBaseClassOffset(derived, pathBegin, pathEnd);
@@ -1624,8 +1619,7 @@ CIRGenFunction::getAddressOfBaseClass(Address Value,
16241619
// *start* with a step down to the correct virtual base subobject,
16251620
// and hence will not require any further steps.
16261621
if ((*Start)->isVirtual()) {
1627-
VBase = cast<CXXRecordDecl>(
1628-
(*Start)->getType()->castAs<RecordType>()->getOriginalDecl());
1622+
VBase = (*Start)->getType()->getAsCXXRecordDecl();
16291623
++Start;
16301624
}
16311625

@@ -1873,8 +1867,8 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
18731867
// Note that these are complete objects and so we don't need to
18741868
// use the non-virtual size or alignment.
18751869
QualType type = getContext().getTypeDeclType(ElaboratedTypeKeyword::None,
1876-
/*Qualifier=*/std::nullopt,
1877-
ctor->getParent());
1870+
/*Qualifier=*/std::nullopt,
1871+
ctor->getParent());
18781872
CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement(
18791873
getContext().getTypeSizeInChars(type));
18801874

@@ -1992,7 +1986,8 @@ void CIRGenFunction::emitCXXConstructorCall(
19921986

19931987
if (!NewPointerIsChecked)
19941988
emitTypeCheck(CIRGenFunction::TCK_ConstructorCall, Loc, This.getPointer(),
1995-
getContext().getCanonicalTagType(ClassDecl), CharUnits::Zero());
1989+
getContext().getCanonicalTagType(ClassDecl),
1990+
CharUnits::Zero());
19961991

19971992
// If this is a call to a trivial default constructor:
19981993
// In LLVM: do nothing.

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &D,
116116
allocaAddr = ReturnValue;
117117

118118
if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
119-
const auto *RD = RecordTy->getOriginalDecl();
119+
const auto *RD = RecordTy->getDecl();
120120
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
121121
if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
122122
RD->isNonTrivialToPrimitiveDestroy()) {
@@ -858,6 +858,7 @@ void CIRGenFunction::emitDecl(const Decl &D) {
858858
case Decl::MSGuid: // __declspec(uuid("..."))
859859
case Decl::TemplateParamObject:
860860
case Decl::OMPThreadPrivate:
861+
case Decl::OMPGroupPrivate:
861862
case Decl::OMPAllocate:
862863
case Decl::OMPCapturedExpr:
863864
case Decl::OMPRequires:

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ bool CIRGenFunction::hasBooleanRepresentation(QualType Ty) {
576576
return true;
577577

578578
if (const EnumType *ET = Ty->getAs<EnumType>())
579-
return ET->getOriginalDecl()->getIntegerType()->isBooleanType();
579+
return ET->getDecl()->getIntegerType()->isBooleanType();
580580

581581
if (const AtomicType *AT = Ty->getAs<AtomicType>())
582582
return hasBooleanRepresentation(AT->getValueType());
@@ -992,7 +992,8 @@ LValue CIRGenFunction::emitLValueForLambdaField(const FieldDecl *field,
992992
if (hasExplicitObjectParameter) {
993993
llvm_unreachable("ExplicitObjectMemberFunction NYI");
994994
} else {
995-
QualType lambdaTagType = getContext().getCanonicalTagType(field->getParent());
995+
QualType lambdaTagType =
996+
getContext().getCanonicalTagType(field->getParent());
996997
lambdaLV = MakeNaturalAlignAddrLValue(thisValue, lambdaTagType);
997998
}
998999
return emitLValueForField(lambdaLV, field);
@@ -1695,7 +1696,7 @@ static bool isPreserveAIArrayBase(CIRGenFunction &CGF, const Expr *ArrayBase) {
16951696
const auto *PointeeT =
16961697
PtrT->getPointeeType()->getUnqualifiedDesugaredType();
16971698
if (const auto *RecT = dyn_cast<clang::RecordType>(PointeeT))
1698-
return RecT->getOriginalDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
1699+
return RecT->getDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
16991700
return false;
17001701
}
17011702

@@ -2023,10 +2024,7 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *E) {
20232024

20242025
case CK_UncheckedDerivedToBase:
20252026
case CK_DerivedToBase: {
2026-
const auto *DerivedClassTy =
2027-
E->getSubExpr()->getType()->castAs<clang::RecordType>();
2028-
auto *DerivedClassDecl =
2029-
cast<CXXRecordDecl>(DerivedClassTy->getOriginalDecl());
2027+
auto *DerivedClassDecl = E->getSubExpr()->getType()->getAsCXXRecordDecl();
20302028

20312029
LValue LV = emitLValue(E->getSubExpr());
20322030
Address This = LV.getAddress();
@@ -2045,9 +2043,7 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *E) {
20452043
case CK_ToUnion:
20462044
assert(0 && "NYI");
20472045
case CK_BaseToDerived: {
2048-
const auto *derivedClassTy = E->getType()->castAs<RecordType>();
2049-
auto *derivedClassDecl =
2050-
cast<CXXRecordDecl>(derivedClassTy->getOriginalDecl());
2046+
auto *derivedClassDecl = E->getType()->getAsCXXRecordDecl();
20512047

20522048
LValue lv = emitLValue(E->getSubExpr());
20532049

@@ -2315,7 +2311,7 @@ static void pushTemporaryCleanup(CIRGenFunction &CGF,
23152311
->getBaseElementTypeUnsafe()
23162312
->getAs<clang::RecordType>()) {
23172313
// Get the destructor for the reference temporary.
2318-
if (auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getOriginalDecl())) {
2314+
if (auto *ClassDecl = RT->getAsCXXRecordDecl()) {
23192315
if (!ClassDecl->hasTrivialDestructor())
23202316
ReferenceTemporaryDtor = ClassDecl->getDestructor();
23212317
}
@@ -3191,7 +3187,7 @@ static bool isConstantEmittableObjectType(QualType type) {
31913187
// Otherwise, all object types satisfy this except C++ classes with
31923188
// mutable subobjects or non-trivial copy/destroy behavior.
31933189
if (const auto *RT = dyn_cast<clang::RecordType>(type))
3194-
if (const auto *RD = dyn_cast<CXXRecordDecl>(RT->getOriginalDecl()))
3190+
if (const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
31953191
if (RD->hasMutableFields() || !RD->isTrivial())
31963192
return false;
31973193

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ bool AggExprEmitter::TypeRequiresGCollection(QualType T) {
589589
return false;
590590

591591
// Don't mess with non-trivial C++ types.
592-
RecordDecl *Record = RecordTy->getOriginalDecl();
592+
RecordDecl *Record = RecordTy->getDecl();
593593
if (isa<CXXRecordDecl>(Record) &&
594594
(cast<CXXRecordDecl>(Record)->hasNonTrivialCopyConstructor() ||
595595
!cast<CXXRecordDecl>(Record)->hasTrivialDestructor()))
@@ -932,7 +932,7 @@ void AggExprEmitter::VisitCXXStdInitializerListExpr(
932932
Ctx.getAsConstantArrayType(E->getSubExpr()->getType());
933933
assert(ArrayType && "std::initializer_list constructed from non-array");
934934

935-
RecordDecl *Record = E->getType()->castAs<RecordType>()->getOriginalDecl();
935+
RecordDecl *Record = E->getType()->castAs<RecordType>()->getDecl();
936936
RecordDecl::field_iterator Field = Record->field_begin();
937937
assert(Field != Record->field_end() &&
938938
Ctx.hasSameType(Field->getType()->getPointeeType(),
@@ -1297,7 +1297,7 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
12971297
// the disadvantage is that the generated code is more difficult for
12981298
// the optimizer, especially with bitfields.
12991299
unsigned NumInitElements = InitExprs.size();
1300-
RecordDecl *record = ExprToVisit->getType()->castAs<RecordType>()->getOriginalDecl();
1300+
RecordDecl *record = ExprToVisit->getType()->castAs<RecordType>()->getDecl();
13011301

13021302
// We'll need to enter cleanup scopes in case any of the element
13031303
// initializers throws an exception.
@@ -1534,7 +1534,7 @@ static CharUnits GetNumNonZeroBytesInInit(const Expr *E, CIRGenFunction &CGF) {
15341534
// referencee. InitListExprs for unions and arrays can't have references.
15351535
if (const RecordType *RT = E->getType()->getAs<RecordType>()) {
15361536
if (!RT->isUnionType()) {
1537-
RecordDecl *SD = RT->getOriginalDecl();
1537+
RecordDecl *SD = RT->getDecl();
15381538
CharUnits NumNonZeroBytes = CharUnits::Zero();
15391539

15401540
unsigned ILEElement = 0;
@@ -1586,7 +1586,7 @@ static void CheckAggExprForMemSetUse(AggValueSlot &Slot, const Expr *E,
15861586
if (const auto *RT = CGF.getContext()
15871587
.getBaseElementType(E->getType())
15881588
->getAs<RecordType>()) {
1589-
const auto *RD = cast<CXXRecordDecl>(RT->getOriginalDecl());
1589+
const auto *RD = RT->getAsCXXRecordDecl();
15901590
if (RD->hasUserDeclaredConstructor())
15911591
return;
15921592
}
@@ -1661,7 +1661,7 @@ void CIRGenFunction::emitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
16611661

16621662
if (getLangOpts().CPlusPlus) {
16631663
if (const RecordType *RT = Ty->getAs<RecordType>()) {
1664-
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(RT->getOriginalDecl())) {
1664+
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
16651665
assert((Record->hasTrivialCopyConstructor() ||
16661666
Record->hasTrivialCopyAssignment() ||
16671667
Record->hasTrivialMoveConstructor() ||
@@ -1734,14 +1734,14 @@ void CIRGenFunction::emitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
17341734
if (CGM.getLangOpts().getGC() == LangOptions::NonGC) {
17351735
// fall through
17361736
} else if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
1737-
RecordDecl *Record = RecordTy->getOriginalDecl();
1737+
RecordDecl *Record = RecordTy->getDecl();
17381738
if (Record->hasObjectMember()) {
17391739
llvm_unreachable("ObjC is NYI");
17401740
}
17411741
} else if (Ty->isArrayType()) {
17421742
QualType BaseType = getContext().getBaseElementType(Ty);
17431743
if (const RecordType *RecordTy = BaseType->getAs<RecordType>()) {
1744-
if (RecordTy->getOriginalDecl()->hasObjectMember()) {
1744+
if (RecordTy->getDecl()->hasObjectMember()) {
17451745
llvm_unreachable("ObjC is NYI");
17461746
}
17471747
}

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ static CXXRecordDecl *getCXXRecord(const Expr *E) {
103103
QualType T = E->getType();
104104
if (const PointerType *PTy = T->getAs<PointerType>())
105105
T = PTy->getPointeeType();
106-
const RecordType *Ty = T->castAs<RecordType>();
107-
return cast<CXXRecordDecl>(Ty->getOriginalDecl());
106+
return T->getAsCXXRecordDecl();
108107
}
109108

110109
RValue
@@ -1209,7 +1208,7 @@ static bool EmitObjectDelete(CIRGenFunction &CGF, const CXXDeleteExpr *DE,
12091208
// destructor is virtual, we'll just emit the vcall and return.
12101209
const CXXDestructorDecl *Dtor = nullptr;
12111210
if (const RecordType *RT = ElementType->getAs<RecordType>()) {
1212-
CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getOriginalDecl());
1211+
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
12131212
if (RD->hasDefinition() && !RD->hasTrivialDestructor()) {
12141213
Dtor = RD->getDestructor();
12151214

0 commit comments

Comments
 (0)