https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/237950
None >From 684bf228a11e264a078f1eb17c5b3e265c695d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 2 Nov 2026 12:57:52 +0100 Subject: [PATCH] [clang][bytecode] Use `Type::castAsCXXRecordDecl()` where appropriate --- clang/lib/AST/ByteCode/Compiler.cpp | 20 +++++++++----------- clang/lib/AST/ByteCode/Context.cpp | 4 ++-- clang/lib/AST/ByteCode/Interp.cpp | 4 ++-- clang/lib/AST/ByteCode/Pointer.cpp | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index dc59a12bbde811..12647df7bb5b94 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -524,7 +524,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) { ->castAs<MemberPointerType>() ->getMostRecentCXXRecordDecl(); for (const CXXBaseSpecifier *B : E->path()) { - const CXXRecordDecl *ToDecl = B->getType()->getAsCXXRecordDecl(); + const CXXRecordDecl *ToDecl = B->getType()->castAsCXXRecordDecl(); unsigned DerivedOffset = Ctx.collectBaseOffset(ToDecl, CurDecl); if (!this->emitCastMemberPtrBasePop(DerivedOffset, ToDecl, E)) @@ -553,7 +553,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) { typedef std::reverse_iterator<CastExpr::path_const_iterator> ReverseIter; for (ReverseIter PathI(E->path_end() - 1), PathE(E->path_begin()); PathI != PathE; ++PathI) { - const CXXRecordDecl *ToDecl = (*PathI)->getType()->getAsCXXRecordDecl(); + const CXXRecordDecl *ToDecl = (*PathI)->getType()->castAsCXXRecordDecl(); unsigned DerivedOffset = Ctx.collectBaseOffset(CurDecl, ToDecl); if (!this->emitCastMemberPtrDerivedPop(-DerivedOffset, ToDecl, E)) @@ -579,8 +579,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) { const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * { if (const auto *PT = dyn_cast<PointerType>(Ty)) - return PT->getPointeeType()->getAsCXXRecordDecl(); - return Ty->getAsCXXRecordDecl(); + return PT->getPointeeType()->castAsCXXRecordDecl(); + return Ty->castAsCXXRecordDecl(); }; // FIXME: We can express a series of non-virtual casts as a single @@ -3946,7 +3946,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) { if (Ctor->isDefaulted() && Ctor->isCopyOrMoveConstructor() && Ctor->isTrivial() && E->getArg(0)->isTemporaryObject(Ctx.getASTContext(), - T->getAsCXXRecordDecl())) + T->castAsCXXRecordDecl())) return this->visitInitializer(E->getArg(0)); // Zero initialization. @@ -6564,7 +6564,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) { if (isa<CXXThisExpr>(Stripped)) { FuncDecl = cast<CXXMethodDecl>(FuncDecl)->getCorrespondingMethodInClass( - Stripped->getType()->getPointeeType()->getAsCXXRecordDecl()); + Stripped->getType()->getPointeeType()->castAsCXXRecordDecl()); Devirtualized = true; if (!this->visit(Stripped)) return false; @@ -7762,8 +7762,7 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) { LocalScope<Emitter> VirtLocalScope(this); if (const Type *Base = Init->getBaseClass(); Base && Init->isBaseVirtual()) { - const auto *BaseDecl = Base->getAsCXXRecordDecl(); - assert(BaseDecl); + const auto *BaseDecl = Base->castAsCXXRecordDecl(); assert(R->findVirtualBase(BaseDecl)); if (!this->emitGetPtrThisVirtBase(BaseDecl, Ctor)) return false; @@ -7793,8 +7792,7 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) { return false; ++FieldInits; } else if (const Type *Base = Init->getBaseClass()) { - const auto *BaseDecl = Base->getAsCXXRecordDecl(); - assert(BaseDecl); + const auto *BaseDecl = Base->castAsCXXRecordDecl(); if (Init->isBaseVirtual()) { // See above. @@ -8763,7 +8761,7 @@ unsigned Compiler<Emitter>::collectBaseOffset(const QualType BaseType, const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * { if (const auto *R = Ty->getPointeeCXXRecordDecl()) return R; - return Ty->getAsCXXRecordDecl(); + return Ty->castAsCXXRecordDecl(); }; const CXXRecordDecl *BaseDecl = extractRecordDecl(BaseType); const CXXRecordDecl *DerivedDecl = extractRecordDecl(DerivedType); diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 378a1f6f6538b1..0a0ed5fc394c86 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -651,13 +651,13 @@ Context::getOverridingFunction(const CXXRecordDecl *DynamicDecl, // Common case of only one base class. if (CurRecord->getNumBases() == 1) { - CurRecord = CurRecord->bases_begin()->getType()->getAsCXXRecordDecl(); + CurRecord = CurRecord->bases_begin()->getType()->castAsCXXRecordDecl(); continue; } // Otherwise, go to the base class that will lead to the StaticDecl. for (const CXXBaseSpecifier &Spec : CurRecord->bases()) { - const CXXRecordDecl *Base = Spec.getType()->getAsCXXRecordDecl(); + const CXXRecordDecl *Base = Spec.getType()->castAsCXXRecordDecl(); if (Base == StaticDecl || Base->isDerivedFrom(StaticDecl)) { CurRecord = Base; break; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 4d3ee95df216c0..1f5e761af888fc 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -2416,7 +2416,7 @@ bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr, { CXXBasePaths Paths; getRecord(LimitedPtr) - ->isDerivedFrom(TargetType->getAsCXXRecordDecl(), Paths); + ->isDerivedFrom(TargetType->castAsCXXRecordDecl(), Paths); if (std::distance(Paths.begin(), Paths.end()) == 0 && !typesMatch(LimitedPtr.getType(), TargetType)) { return diag(DiagNoBase, TargetType); @@ -2548,7 +2548,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func, Func = S.getContext().getOrCreateFunction(Overrider); const CXXRecordDecl *ThisFieldDecl = - ThisPtr.getFieldDesc()->getType()->getAsCXXRecordDecl(); + ThisPtr.getFieldDesc()->getType()->castAsCXXRecordDecl(); if (Func->getParentDecl()->isDerivedFrom(ThisFieldDecl)) { // If the function we call is further DOWN the hierarchy than the // FieldDesc of our pointer, just go up the hierarchy of this field diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 35ffa4e68373a8..7500ddfe2f17da 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -1402,7 +1402,7 @@ OpaquePointer::computeLayoutOffset(const ASTContext &ASTCtx) const { for (const PointerPathEntry &Entry : path()) { switch (Entry.Kind) { case PointerPathEntry::Base: { - const CXXRecordDecl *RD = CurType->getAsCXXRecordDecl(); + const CXXRecordDecl *RD = CurType->castAsCXXRecordDecl(); if (!ASTContext::hasLayout(RD)) return std::nullopt; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
