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
5 changes: 2 additions & 3 deletions clang-tools-extra/clang-doc/Serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,8 @@ parseBases(RecordInfo &I, const CXXRecordDecl *D, bool IsFileInRootDir,
if (!D->isThisDeclarationADefinition())
return;
for (const CXXBaseSpecifier &B : D->bases()) {
if (const RecordType *Ty = B.getType()->getAs<RecordType>()) {
if (const CXXRecordDecl *Base = cast_or_null<CXXRecordDecl>(
Ty->getOriginalDecl()->getDefinition())) {
if (const auto *Base = B.getType()->getAsCXXRecordDecl()) {
if (Base->isCompleteDefinition()) {
// Initialized without USR and name, this will be set in the following
// if-else stmt.
BaseRecordInfo BI(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void DefaultOperatorNewAlignmentCheck::check(
return;
const TagDecl *D = T->getAsTagDecl();
// Alignment can not be obtained for undefined type.
if (!D || !D->getDefinition() || !D->isCompleteDefinition())
if (!D || !D->isCompleteDefinition())
return;

ASTContext &Context = D->getASTContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ void SlicingCheck::diagnoseSlicedOverriddenMethods(
}
// Recursively process bases.
for (const auto &Base : DerivedDecl.bases()) {
if (const auto *BaseRecordType = Base.getType()->getAs<RecordType>()) {
if (const auto *BaseRecord = cast_or_null<CXXRecordDecl>(
BaseRecordType->getOriginalDecl()->getDefinition()))
if (const auto *BaseRecord = Base.getType()->getAsCXXRecordDecl()) {
if (BaseRecord->isCompleteDefinition())
diagnoseSlicedOverriddenMethods(Call, *BaseRecord, BaseDecl);
}
}
Expand Down
23 changes: 9 additions & 14 deletions clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
for (const auto &I : Node->bases()) {
if (I.isVirtual())
continue;
const auto *Ty = I.getType()->getAs<RecordType>();
if (!Ty)
const auto *Base = I.getType()->getAsCXXRecordDecl();
if (!Base)
continue;
const RecordDecl *D = Ty->getOriginalDecl()->getDefinition();
if (!D)
continue;
const auto *Base = cast<CXXRecordDecl>(D);
assert(Base->isCompleteDefinition());
if (!isInterface(Base)) {
addNodeToInterfaceMap(Node, false);
return false;
Expand All @@ -103,23 +100,21 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
for (const auto &I : D->bases()) {
if (I.isVirtual())
continue;
const auto *Ty = I.getType()->getAs<RecordType>();
if (!Ty)
const auto *Base = I.getType()->getAsCXXRecordDecl();
if (!Base)
continue;
const auto *Base =
cast<CXXRecordDecl>(Ty->getOriginalDecl()->getDefinition());
assert(Base->isCompleteDefinition());
if (!isInterface(Base))
NumConcrete++;
}

// Check virtual bases to see if there is more than one concrete
// non-virtual base.
for (const auto &V : D->vbases()) {
const auto *Ty = V.getType()->getAs<RecordType>();
if (!Ty)
const auto *Base = V.getType()->getAsCXXRecordDecl();
if (!Base)
continue;
const auto *Base =
cast<CXXRecordDecl>(Ty->getOriginalDecl()->getDefinition());
assert(Base->isCompleteDefinition());
if (!isInterface(Base))
NumConcrete++;
}
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
return true;

if (const auto *RT = CanonicalType->getAs<RecordType>()) {
return recordIsTriviallyDefaultConstructible(
*RT->getOriginalDecl()->getDefinitionOrSelf(), Context);
if (const auto *RD = CanonicalType->getAsRecordDecl()) {
return recordIsTriviallyDefaultConstructible(*RD, Context);
}

// No other types can match.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/AbstractBasicReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
auto elemTy = origTy;
unsigned pathLength = asImpl().readUInt32();
for (unsigned i = 0; i < pathLength; ++i) {
if (elemTy->template getAs<RecordType>()) {
if (elemTy->isRecordType()) {
unsigned int_ = asImpl().readUInt32();
Decl *decl = asImpl().template readDeclAs<Decl>();
if (auto *recordDecl = dyn_cast<CXXRecordDecl>(decl))
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/AbstractBasicWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
asImpl().writeUInt32(path.size());
auto &ctx = ((BasicWriterBase<Impl> *)this)->getASTContext();
for (auto elem : path) {
if (elemTy->getAs<RecordType>()) {
if (elemTy->isRecordType()) {
asImpl().writeUInt32(elem.getAsBaseOrMember().getInt());
const Decl *baseOrMember = elem.getAsBaseOrMember().getPointer();
if (const auto *recordDecl = dyn_cast<CXXRecordDecl>(baseOrMember)) {
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -3825,7 +3825,9 @@ class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> {
void setEnumType(TypeSourceInfo *TSI) { EnumType = TSI; }

public:
EnumDecl *getEnumDecl() const { return cast<EnumDecl>(EnumType->getType()->getAsTagDecl()); }
EnumDecl *getEnumDecl() const {
return cast<clang::EnumType>(EnumType->getType())->getOriginalDecl();
}

static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation UsingL, SourceLocation EnumL,
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -5404,7 +5404,7 @@ class Sema final : public SemaBase {

/// FinalizeVarWithDestructor - Prepare for calling destructor on the
/// constructed variable.
void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
void FinalizeVarWithDestructor(VarDecl *VD, CXXRecordDecl *DeclInit);

/// Helper class that collects exception specifications for
/// implicitly-declared special member functions.
Expand Down
34 changes: 12 additions & 22 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ comments::FullComment *ASTContext::getCommentForDecl(
// does not have one of its own.
QualType QT = TD->getUnderlyingType();
if (const auto *TT = QT->getAs<TagType>())
if (const Decl *TD = TT->getOriginalDecl())
if (comments::FullComment *FC = getCommentForDecl(TD, PP))
return cloneFullComment(FC, D);
if (comments::FullComment *FC =
getCommentForDecl(TT->getOriginalDecl(), PP))
return cloneFullComment(FC, D);
}
else if (const auto *IC = dyn_cast<ObjCInterfaceDecl>(D)) {
while (IC->getSuperClass()) {
Expand Down Expand Up @@ -1933,12 +1933,9 @@ TypeInfoChars ASTContext::getTypeInfoDataSizeInChars(QualType T) const {
// of a base-class subobject. We decide whether that's possible
// during class layout, so here we can just trust the layout results.
if (getLangOpts().CPlusPlus) {
if (const auto *RT = T->getAs<RecordType>()) {
const auto *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
if (!RD->isInvalidDecl()) {
const ASTRecordLayout &layout = getASTRecordLayout(RD);
Info.Width = layout.getDataSize();
}
if (const auto *RD = T->getAsCXXRecordDecl(); RD && !RD->isInvalidDecl()) {
const ASTRecordLayout &layout = getASTRecordLayout(RD);
Info.Width = layout.getDataSize();
}
}

Expand Down Expand Up @@ -2694,9 +2691,7 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
if (!Target->allowsLargerPreferedTypeAlignment())
return ABIAlign;

if (const auto *RT = T->getAs<RecordType>()) {
const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf();

if (const auto *RD = T->getAsRecordDecl()) {
// When used as part of a typedef, or together with a 'packed' attribute,
// the 'aligned' attribute can be used to decrease alignment. Note that the
// 'packed' case is already taken into consideration when computing the
Expand Down Expand Up @@ -2887,12 +2882,10 @@ structHasUniqueObjectRepresentations(const ASTContext &Context,
static std::optional<int64_t>
getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context,
bool CheckIfTriviallyCopyable) {
if (Field->getType()->isRecordType()) {
const RecordDecl *RD = Field->getType()->getAsRecordDecl();
if (!RD->isUnion())
return structHasUniqueObjectRepresentations(Context, RD,
CheckIfTriviallyCopyable);
}
if (const auto *RD = Field->getType()->getAsRecordDecl();
RD && !RD->isUnion())
return structHasUniqueObjectRepresentations(Context, RD,
CheckIfTriviallyCopyable);

// A _BitInt type may not be unique if it has padding bits
// but if it is a bitfield the padding bits are not used.
Expand Down Expand Up @@ -3047,10 +3040,7 @@ bool ASTContext::hasUniqueObjectRepresentations(
if (const auto *MPT = Ty->getAs<MemberPointerType>())
return !ABI->getMemberPointerInfo(MPT).HasPadding;

if (Ty->isRecordType()) {
const RecordDecl *Record =
Ty->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf();

if (const auto *Record = Ty->getAsRecordDecl()) {
if (Record->isInvalidDecl())
return false;

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ASTStructuralEquivalence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,10 +878,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
// Treat the enumeration as its underlying type and use the builtin type
// class comparison.
if (T1->getTypeClass() == Type::Enum) {
T1 = T1->getAs<EnumType>()->getOriginalDecl()->getIntegerType();
T1 = cast<EnumType>(T1)->getOriginalDecl()->getIntegerType();
assert(T2->isBuiltinType() && !T1.isNull()); // Sanity check
} else if (T2->getTypeClass() == Type::Enum) {
T2 = T2->getAs<EnumType>()->getOriginalDecl()->getIntegerType();
T2 = cast<EnumType>(T2)->getOriginalDecl()->getIntegerType();
assert(T1->isBuiltinType() && !T2.isNull()); // Sanity check
}
TC = Type::Builtin;
Expand Down
21 changes: 7 additions & 14 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3303,11 +3303,8 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
switch (Node.getKind()) {
case OffsetOfNode::Field: {
const FieldDecl *MemberDecl = Node.getField();
const RecordType *RT = CurrentType->getAs<RecordType>();
if (!RT)
return false;
const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
if (RD->isInvalidDecl())
const auto *RD = CurrentType->getAsRecordDecl();
if (!RD || RD->isInvalidDecl())
return false;
const ASTRecordLayout &RL = S.getASTContext().getASTRecordLayout(RD);
unsigned FieldIndex = MemberDecl->getFieldIndex();
Expand Down Expand Up @@ -3336,23 +3333,19 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
return false;

// Find the layout of the class whose base we are looking into.
const RecordType *RT = CurrentType->getAs<RecordType>();
if (!RT)
return false;
const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
if (RD->isInvalidDecl())
const auto *RD = CurrentType->getAsCXXRecordDecl();
if (!RD || RD->isInvalidDecl())
return false;
const ASTRecordLayout &RL = S.getASTContext().getASTRecordLayout(RD);

// Find the base class itself.
CurrentType = BaseSpec->getType();
const RecordType *BaseRT = CurrentType->getAs<RecordType>();
if (!BaseRT)
const auto *BaseRD = CurrentType->getAsCXXRecordDecl();
if (!BaseRD)
return false;

// Add the offset to the base.
Result += RL.getBaseClassOffset(cast<CXXRecordDecl>(
BaseRT->getOriginalDecl()->getDefinitionOrSelf()));
Result += RL.getBaseClassOffset(BaseRD);
break;
}
case OffsetOfNode::Identifier:
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/AST/ByteCode/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,9 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
continue;

// In error cases, the base might not be a RecordType.
const auto *RT = Spec.getType()->getAs<RecordType>();
if (!RT)
const auto *BD = Spec.getType()->getAsCXXRecordDecl();
if (!BD)
return nullptr;
const RecordDecl *BD = RT->getOriginalDecl()->getDefinitionOrSelf();
const Record *BR = getOrCreateRecord(BD);

const Descriptor *Desc = GetBaseDesc(BD, BR);
Expand Down Expand Up @@ -408,9 +407,8 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
const Expr *Init) {

// Classes and structures.
if (const auto *RT = Ty->getAs<RecordType>()) {
if (const auto *Record =
getOrCreateRecord(RT->getOriginalDecl()->getDefinitionOrSelf()))
if (const auto *RD = Ty->getAsRecordDecl()) {
if (const auto *Record = getOrCreateRecord(RD))
return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
IsMutable, IsVolatile);
return allocateDescriptor(D, MDSize);
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/AST/ByteCode/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ const Record::Base *Record::getBase(const RecordDecl *FD) const {
}

const Record::Base *Record::getBase(QualType T) const {
if (auto *RT = T->getAs<RecordType>()) {
const RecordDecl *RD = RT->getOriginalDecl()->getDefinitionOrSelf();
if (auto *RD = T->getAsCXXRecordDecl())
return BaseMap.lookup(RD);
}
return nullptr;
}

Expand Down
27 changes: 7 additions & 20 deletions clang/lib/AST/CXXInheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,11 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback BaseMatches) const {
const CXXRecordDecl *Record = this;
while (true) {
for (const auto &I : Record->bases()) {
const RecordType *Ty = I.getType()->getAs<RecordType>();
if (!Ty)
const auto *Base = I.getType()->getAsCXXRecordDecl();
if (!Base || !(Base->isBeingDefined() || Base->isCompleteDefinition()))
return false;

CXXRecordDecl *Base = cast_if_present<CXXRecordDecl>(
Ty->getOriginalDecl()->getDefinition());
if (!Base ||
(Base->isDependentContext() &&
!Base->isCurrentInstantiation(Record))) {
if (Base->isDependentContext() && !Base->isCurrentInstantiation(Record))
return false;
}

Queue.push_back(Base);
if (!BaseMatches(Base))
Expand Down Expand Up @@ -255,9 +249,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
const TemplateSpecializationType *TST =
BaseSpec.getType()->getAs<TemplateSpecializationType>();
if (!TST) {
if (auto *RT = BaseSpec.getType()->getAs<RecordType>())
BaseRecord = cast<CXXRecordDecl>(RT->getOriginalDecl())
->getDefinitionOrSelf();
BaseRecord = BaseSpec.getType()->getAsCXXRecordDecl();
} else {
TemplateName TN = TST->getTemplateName();
if (auto *TD =
Expand Down Expand Up @@ -347,11 +339,8 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback BaseMatches,
// base is a subobject of any other path; if so, then the
// declaration in this path are hidden by that patch.
for (const CXXBasePath &HidingP : Paths) {
CXXRecordDecl *HidingClass = nullptr;
if (const RecordType *Record =
HidingP.back().Base->getType()->getAs<RecordType>())
HidingClass = cast<CXXRecordDecl>(Record->getOriginalDecl())
->getDefinitionOrSelf();
auto *HidingClass =
HidingP.back().Base->getType()->getAsCXXRecordDecl();
if (!HidingClass)
break;

Expand Down Expand Up @@ -470,9 +459,7 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD,
= ++SubobjectCount[cast<CXXRecordDecl>(RD->getCanonicalDecl())];

for (const auto &Base : RD->bases()) {
if (const RecordType *RT = Base.getType()->getAs<RecordType>()) {
const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(RT->getOriginalDecl())->getDefinitionOrSelf();
if (const auto *BaseDecl = Base.getType()->getAsCXXRecordDecl()) {
if (!BaseDecl->isPolymorphic())
continue;

Expand Down
20 changes: 7 additions & 13 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2861,9 +2861,8 @@ VarDecl::needsDestruction(const ASTContext &Ctx) const {

bool VarDecl::hasFlexibleArrayInit(const ASTContext &Ctx) const {
assert(hasInit() && "Expect initializer to check for flexible array init");
auto *Ty = getType()->getAs<RecordType>();
if (!Ty ||
!Ty->getOriginalDecl()->getDefinitionOrSelf()->hasFlexibleArrayMember())
auto *D = getType()->getAsRecordDecl();
if (!D || !D->hasFlexibleArrayMember())
return false;
auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens());
if (!List)
Expand All @@ -2877,11 +2876,8 @@ bool VarDecl::hasFlexibleArrayInit(const ASTContext &Ctx) const {

CharUnits VarDecl::getFlexibleArrayInitChars(const ASTContext &Ctx) const {
assert(hasInit() && "Expect initializer to check for flexible array init");
auto *Ty = getType()->getAs<RecordType>();
if (!Ty)
return CharUnits::Zero();
const RecordDecl *RD = Ty->getOriginalDecl()->getDefinitionOrSelf();
if (!Ty || !RD->hasFlexibleArrayMember())
auto *RD = getType()->getAsRecordDecl();
if (!RD || !RD->hasFlexibleArrayMember())
return CharUnits::Zero();
auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens());
if (!List || List->getNumInits() == 0)
Expand Down Expand Up @@ -4738,7 +4734,7 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
// MS ABI: has nonzero size if it is a class type with class type fields,
// whether or not they have nonzero size
return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
return Field->getType()->getAs<RecordType>();
return Field->getType()->isRecordType();
});
}

Expand Down Expand Up @@ -5274,10 +5270,8 @@ const FieldDecl *RecordDecl::findFirstNamedDataMember() const {
if (I->getIdentifier())
return I;

if (const auto *RT = I->getType()->getAs<RecordType>())
if (const FieldDecl *NamedDataMember = RT->getOriginalDecl()
->getDefinitionOrSelf()
->findFirstNamedDataMember())
if (const auto *RD = I->getType()->getAsRecordDecl())
if (const FieldDecl *NamedDataMember = RD->findFirstNamedDataMember())
return NamedDataMember;
}

Expand Down
Loading
Loading