Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang/lib/CIR/CodeGen/CIRGenCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ bool CIRGenModule::tryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
continue;

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

Expand Down
11 changes: 5 additions & 6 deletions clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const Expr *E,
// However, we still have to push an EH-only cleanup in case we unwind before
// we make it to the call.
if (type->isRecordType() &&
type->castAs<RecordType>()->getOriginalDecl()->isParamDestroyedInCallee()) {
type->getAsRecordDecl()->isParamDestroyedInCallee()) {
llvm_unreachable("Microsoft C++ ABI is NYI");
}

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

const CIRGenFunctionInfo &
Expand Down Expand Up @@ -1218,7 +1217,7 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args,

// Deactivate the cleanup for the callee-destructed param that was pushed.
if (type->isRecordType() && !CurFuncIsThunk &&
type->castAs<RecordType>()->getOriginalDecl()->isParamDestroyedInCallee() &&
type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() &&
param->needsDestruction(getContext())) {
llvm_unreachable("NYI");
}
Expand Down
43 changes: 19 additions & 24 deletions clang/lib/CIR/CodeGen/CIRGenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class FieldMemcpyizer {

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

static bool isInitializerOfDynamicClass(const CXXCtorInitializer *BaseInit) {
const Type *BaseType = BaseInit->getBaseClass();
const auto *BaseClassDecl =
cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getOriginalDecl());
const auto *BaseClassDecl = BaseType->castAsCXXRecordDecl();
return BaseClassDecl->isDynamicClass();
}

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

const Type *BaseType = BaseInit->getBaseClass();
const auto *BaseClassDecl =
cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getOriginalDecl());
const auto *BaseClassDecl = BaseType->getAsCXXRecordDecl();

bool isBaseVirtual = BaseInit->isBaseVirtual();

Expand Down Expand Up @@ -871,8 +869,7 @@ void CIRGenFunction::getVTablePointers(BaseSubobject Base,

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

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

const CXXRecordDecl *NonVirtualBase =
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
const CXXRecordDecl *NonVirtualBase = I.getType()->getAsCXXRecordDecl();
if (!HasTrivialDestructorBody(astContext, NonVirtualBase,
MostDerivedClassDecl))
return false;
Expand All @@ -1133,8 +1129,7 @@ HasTrivialDestructorBody(ASTContext &astContext,
if (BaseClassDecl == MostDerivedClassDecl) {
// Check virtual bases.
for (const auto &I : BaseClassDecl->vbases()) {
const CXXRecordDecl *VirtualBase =
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getOriginalDecl());
const CXXRecordDecl *VirtualBase = I.getType()->getAsCXXRecordDecl();
if (!HasTrivialDestructorBody(astContext, VirtualBase,
MostDerivedClassDecl))
return false;
Expand All @@ -1154,7 +1149,7 @@ static bool FieldHasTrivialDestructorBody(ASTContext &astContext,
if (!RT)
return true;

CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getOriginalDecl());
CXXRecordDecl *FieldClassDecl = RT->getAsCXXRecordDecl();

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

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

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

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

QualType derivedTy =
getContext().getCanonicalTagType(derived);
QualType derivedTy = getContext().getCanonicalTagType(derived);
mlir::Type derivedValueTy = convertType(derivedTy);
CharUnits nonVirtualOffset =
CGM.getNonVirtualBaseClassOffset(derived, pathBegin, pathEnd);
Expand Down Expand Up @@ -1624,8 +1619,7 @@ CIRGenFunction::getAddressOfBaseClass(Address Value,
// *start* with a step down to the correct virtual base subobject,
// and hence will not require any further steps.
if ((*Start)->isVirtual()) {
VBase = cast<CXXRecordDecl>(
(*Start)->getType()->castAs<RecordType>()->getOriginalDecl());
VBase = (*Start)->getType()->getAsCXXRecordDecl();
++Start;
}

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

Expand Down Expand Up @@ -1992,7 +1986,8 @@ void CIRGenFunction::emitCXXConstructorCall(

if (!NewPointerIsChecked)
emitTypeCheck(CIRGenFunction::TCK_ConstructorCall, Loc, This.getPointer(),
getContext().getCanonicalTagType(ClassDecl), CharUnits::Zero());
getContext().getCanonicalTagType(ClassDecl),
CharUnits::Zero());

// If this is a call to a trivial default constructor:
// In LLVM: do nothing.
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &D,
allocaAddr = ReturnValue;

if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
const auto *RD = RecordTy->getOriginalDecl();
const auto *RD = RecordTy->getDecl();
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
RD->isNonTrivialToPrimitiveDestroy()) {
Expand Down Expand Up @@ -858,6 +858,7 @@ void CIRGenFunction::emitDecl(const Decl &D) {
case Decl::MSGuid: // __declspec(uuid("..."))
case Decl::TemplateParamObject:
case Decl::OMPThreadPrivate:
case Decl::OMPGroupPrivate:
case Decl::OMPAllocate:
case Decl::OMPCapturedExpr:
case Decl::OMPRequires:
Expand Down
20 changes: 8 additions & 12 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ bool CIRGenFunction::hasBooleanRepresentation(QualType Ty) {
return true;

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

if (const AtomicType *AT = Ty->getAs<AtomicType>())
return hasBooleanRepresentation(AT->getValueType());
Expand Down Expand Up @@ -992,7 +992,8 @@ LValue CIRGenFunction::emitLValueForLambdaField(const FieldDecl *field,
if (hasExplicitObjectParameter) {
llvm_unreachable("ExplicitObjectMemberFunction NYI");
} else {
QualType lambdaTagType = getContext().getCanonicalTagType(field->getParent());
QualType lambdaTagType =
getContext().getCanonicalTagType(field->getParent());
lambdaLV = MakeNaturalAlignAddrLValue(thisValue, lambdaTagType);
}
return emitLValueForField(lambdaLV, field);
Expand Down Expand Up @@ -1695,7 +1696,7 @@ static bool isPreserveAIArrayBase(CIRGenFunction &CGF, const Expr *ArrayBase) {
const auto *PointeeT =
PtrT->getPointeeType()->getUnqualifiedDesugaredType();
if (const auto *RecT = dyn_cast<clang::RecordType>(PointeeT))
return RecT->getOriginalDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
return RecT->getDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
return false;
}

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

case CK_UncheckedDerivedToBase:
case CK_DerivedToBase: {
const auto *DerivedClassTy =
E->getSubExpr()->getType()->castAs<clang::RecordType>();
auto *DerivedClassDecl =
cast<CXXRecordDecl>(DerivedClassTy->getOriginalDecl());
auto *DerivedClassDecl = E->getSubExpr()->getType()->getAsCXXRecordDecl();

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

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

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

Expand Down
16 changes: 8 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ bool AggExprEmitter::TypeRequiresGCollection(QualType T) {
return false;

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

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

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

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

if (getLangOpts().CPlusPlus) {
if (const RecordType *RT = Ty->getAs<RecordType>()) {
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(RT->getOriginalDecl())) {
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
assert((Record->hasTrivialCopyConstructor() ||
Record->hasTrivialCopyAssignment() ||
Record->hasTrivialMoveConstructor() ||
Expand Down Expand Up @@ -1734,14 +1734,14 @@ void CIRGenFunction::emitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
if (CGM.getLangOpts().getGC() == LangOptions::NonGC) {
// fall through
} else if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
RecordDecl *Record = RecordTy->getOriginalDecl();
RecordDecl *Record = RecordTy->getDecl();
if (Record->hasObjectMember()) {
llvm_unreachable("ObjC is NYI");
}
} else if (Ty->isArrayType()) {
QualType BaseType = getContext().getBaseElementType(Ty);
if (const RecordType *RecordTy = BaseType->getAs<RecordType>()) {
if (RecordTy->getOriginalDecl()->hasObjectMember()) {
if (RecordTy->getDecl()->hasObjectMember()) {
llvm_unreachable("ObjC is NYI");
}
}
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ static CXXRecordDecl *getCXXRecord(const Expr *E) {
QualType T = E->getType();
if (const PointerType *PTy = T->getAs<PointerType>())
T = PTy->getPointeeType();
const RecordType *Ty = T->castAs<RecordType>();
return cast<CXXRecordDecl>(Ty->getOriginalDecl());
return T->getAsCXXRecordDecl();
}

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

Expand Down
Loading
Loading