Author: Michael Liao Date: 2025-08-09T16:38:49-04:00 New Revision: c9b62427716f41cf33b932a5622d8ef5b588f1c0
URL: https://github.com/llvm/llvm-project/commit/c9b62427716f41cf33b932a5622d8ef5b588f1c0 DIFF: https://github.com/llvm/llvm-project/commit/c9b62427716f41cf33b932a5622d8ef5b588f1c0.diff LOG: [CIR] Fix build after the improved nested name specifier AST repr (91cdd35008e9) Added: Modified: clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp clang/lib/CIR/CodeGen/CIRGenCall.cpp clang/lib/CIR/CodeGen/CIRGenClass.cpp clang/lib/CIR/CodeGen/CIRGenExpr.cpp clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp clang/lib/CIR/CodeGen/CIRGenFunction.cpp clang/lib/CIR/CodeGen/CIRGenFunction.h clang/lib/CIR/CodeGen/CIRGenModule.cpp clang/lib/CIR/CodeGen/CIRGenTypes.cpp clang/lib/CIR/CodeGen/TargetInfo.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp index 67d8988a5fbbd..bc30c7bd130af 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCXXExpr.cpp @@ -75,7 +75,7 @@ static MemberCallInfo commonBuildCXXMemberOrOperatorCall( RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr( const CallExpr *ce, const CXXMethodDecl *md, ReturnValueSlot returnValue, - bool hasQualifier, NestedNameSpecifier *qualifier, bool isArrow, + bool hasQualifier, NestedNameSpecifier qualifier, bool isArrow, const Expr *base) { assert(isa<CXXMemberCallExpr>(ce) || isa<CXXOperatorCallExpr>(ce)); @@ -169,7 +169,7 @@ CIRGenFunction::emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e, assert(md->isInstance() && "Trying to emit a member call expr on a static method!"); return emitCXXMemberOrOperatorMemberCallExpr( - e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr, + e, md, returnValue, /*HasQualifier=*/false, /*Qualifier=*/std::nullopt, /*IsArrow=*/false, e->getArg(0)); } diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index fc208fffe216f..adf0ca1a1fe93 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -203,9 +203,9 @@ CIRGenTypes::arrangeCXXStructorDeclaration(GlobalDecl gd) { /// when calling a method pointer. CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd, const CXXMethodDecl *md) { - QualType recTy; + CanQualType recTy; if (rd) { - recTy = getASTContext().getTagDeclType(rd)->getCanonicalTypeInternal(); + recTy = getASTContext().getCanonicalTagType(rd); } else { // This can happen with the MS ABI. It shouldn't need anything more than // setting recTy to VoidTy here, but we're flagging it for now because we @@ -215,9 +215,9 @@ CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd, } if (md) - recTy = getASTContext().getAddrSpaceQualType( - recTy, md->getMethodQualifiers().getAddressSpace()); - return getASTContext().getPointerType(CanQualType::CreateUnsafe(recTy)); + recTy = CanQualType::CreateUnsafe(getASTContext().getAddrSpaceQualType( + recTy, md->getMethodQualifiers().getAddressSpace())); + return getASTContext().getPointerType(recTy); } /// Arrange the CIR function layout for a value of the given function type, on @@ -267,7 +267,10 @@ void CIRGenFunction::emitDelegateCallArg(CallArgList &args, // Deactivate the cleanup for the callee-destructed param that was pushed. assert(!cir::MissingFeatures::thunks()); if (type->isRecordType() && - type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() && + type->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf() + ->isParamDestroyedInCallee() && param->needsDestruction(getContext())) { cgm.errorNYI(param->getSourceRange(), "emitDelegateCallArg: callee-destructed param"); @@ -667,8 +670,10 @@ void CIRGenFunction::emitCallArg(CallArgList &args, const clang::Expr *e, // In the Microsoft C++ ABI, aggregate arguments are destructed by the callee. // However, we still have to push an EH-only cleanup in case we unwind before // we make it to the call. - if (argType->isRecordType() && - argType->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) { + if (argType->isRecordType() && argType->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf() + ->isParamDestroyedInCallee()) { assert(!cir::MissingFeatures::msabi()); cgm.errorNYI(e->getSourceRange(), "emitCallArg: msabi is NYI"); } diff --git a/clang/lib/CIR/CodeGen/CIRGenClass.cpp b/clang/lib/CIR/CodeGen/CIRGenClass.cpp index 72b9d177e4c63..46cf2a10e2508 100644 --- a/clang/lib/CIR/CodeGen/CIRGenClass.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenClass.cpp @@ -86,7 +86,7 @@ static void emitMemberInitializer(CIRGenFunction &cgf, QualType fieldType = field->getType(); mlir::Value thisPtr = cgf.loadCXXThis(); - QualType recordTy = cgf.getContext().getTypeDeclType(classDecl); + CanQualType recordTy = cgf.getContext().getCanonicalTagType(classDecl); // If a base constructor is being emitted, create an LValue that has the // non-virtual alignment. @@ -121,7 +121,8 @@ static void emitMemberInitializer(CIRGenFunction &cgf, static bool isInitializerOfDynamicClass(const CXXCtorInitializer *baseInit) { const Type *baseType = baseInit->getBaseClass(); const auto *baseClassDecl = - cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl()) + ->getDefinitionOrSelf(); return baseClassDecl->isDynamicClass(); } @@ -161,7 +162,8 @@ void CIRGenFunction::emitBaseInitializer(mlir::Location loc, const Type *baseType = baseInit->getBaseClass(); const auto *baseClassDecl = - cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(baseType->castAs<RecordType>()->getOriginalDecl()) + ->getDefinitionOrSelf(); bool isBaseVirtual = baseInit->isBaseVirtual(); @@ -377,7 +379,7 @@ 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(ctor->getParent()); + CanQualType type = getContext().getCanonicalTagType(ctor->getParent()); CharUnits eltAlignment = arrayBase.getAlignment().alignmentOfArrayElement( getContext().getTypeSizeInChars(type)); @@ -484,7 +486,8 @@ void CIRGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &args) { void CIRGenFunction::destroyCXXObject(CIRGenFunction &cgf, Address addr, QualType type) { const RecordType *rtype = type->castAs<RecordType>(); - const CXXRecordDecl *record = cast<CXXRecordDecl>(rtype->getDecl()); + const CXXRecordDecl *record = + cast<CXXRecordDecl>(rtype->getOriginalDecl())->getDefinitionOrSelf(); 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 diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index a0ff08ea3de3a..c437b14dd8d1c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -1013,7 +1013,9 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) { case CK_DerivedToBase: { const auto *derivedClassTy = e->getSubExpr()->getType()->castAs<clang::RecordType>(); - auto *derivedClassDecl = cast<CXXRecordDecl>(derivedClassTy->getDecl()); + auto *derivedClassDecl = + cast<CXXRecordDecl>(derivedClassTy->getOriginalDecl()) + ->getDefinitionOrSelf(); LValue lv = emitLValue(e->getSubExpr()); Address thisAddr = lv.getAddress(); @@ -1167,9 +1169,10 @@ static void pushTemporaryCleanup(CIRGenFunction &cgf, ->getBaseElementTypeUnsafe() ->getAs<clang::RecordType>()) { // Get the destructor for the reference temporary. - auto *classDecl = cast<CXXRecordDecl>(rt->getDecl()); + auto *classDecl = cast<CXXRecordDecl>(rt->getOriginalDecl()); if (!classDecl->hasTrivialDestructor()) - referenceTemporaryDtor = classDecl->getDestructor(); + referenceTemporaryDtor = + classDecl->getDefinitionOrSelf()->getDestructor(); } if (!referenceTemporaryDtor) @@ -1831,7 +1834,7 @@ RValue CIRGenFunction::emitCXXMemberCallExpr(const CXXMemberCallExpr *ce, } bool hasQualifier = me->hasQualifier(); - NestedNameSpecifier *qualifier = hasQualifier ? me->getQualifier() : nullptr; + NestedNameSpecifier qualifier = me->getQualifier(); bool isArrow = me->isArrow(); const Expr *base = me->getBase(); diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index 51aab95e02e66..1fda8487796a9 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -376,7 +376,10 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr( // the disadvantage is that the generated code is more diff icult for // the optimizer, especially with bitfields. unsigned numInitElements = args.size(); - RecordDecl *record = e->getType()->castAs<RecordType>()->getDecl(); + RecordDecl *record = e->getType() + ->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf(); // We'll need to enter cleanup scopes in case any of the element // initializers throws an exception. diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index 5b3bf85cefbb0..21e9a8a98e947 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -591,7 +591,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) { // be a problem for the near future. if (cd->isTrivial() && cd->isDefaultConstructor()) { const auto *cxxrd = - cast<CXXRecordDecl>(ty->getAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(ty->getAs<RecordType>()->getOriginalDecl()) + ->getDefinitionOrSelf(); if (cxxrd->getNumBases() != 0) { // There may not be anything additional to do here, but this will // force us to pause and test this path when it is supported. diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index dedd01ce5e685..86f49f0c3c297 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -356,7 +356,8 @@ static bool mayDropFunctionReturn(const ASTContext &astContext, // destructor or a non-trivially copyable type. if (const RecordType *recordType = returnType.getCanonicalType()->getAs<RecordType>()) { - if (const auto *classDecl = dyn_cast<CXXRecordDecl>(recordType->getDecl())) + if (const auto *classDecl = + dyn_cast<CXXRecordDecl>(recordType->getOriginalDecl())) return classDecl->hasTrivialDestructor(); } return returnType.isTriviallyCopyableType(astContext); @@ -827,7 +828,9 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr, // Ignore empty classes in C++. if (getLangOpts().CPlusPlus) { if (const RecordType *rt = ty->getAs<RecordType>()) { - if (cast<CXXRecordDecl>(rt->getDecl())->isEmpty()) + if (cast<CXXRecordDecl>(rt->getOriginalDecl()) + ->getDefinitionOrSelf() + ->isEmpty()) return; } } @@ -978,10 +981,6 @@ void CIRGenFunction::emitVariablyModifiedType(QualType type) { case Type::BitInt: llvm_unreachable("type class is never variably-modified!"); - case Type::Elaborated: - type = cast<clang::ElaboratedType>(ty)->getNamedType(); - break; - case Type::Adjusted: type = cast<clang::AdjustedType>(ty)->getAdjustedType(); break; diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index bdbc77c0a7c4a..68447082a5a1f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -1011,7 +1011,7 @@ class CIRGenFunction : public CIRGenTypeCache { RValue emitCXXMemberOrOperatorMemberCallExpr( const clang::CallExpr *ce, const clang::CXXMethodDecl *md, ReturnValueSlot returnValue, bool hasQualifier, - clang::NestedNameSpecifier *qualifier, bool isArrow, + clang::NestedNameSpecifier qualifier, bool isArrow, const clang::Expr *base); mlir::Value emitCXXNewExpr(const CXXNewExpr *e); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index ff6d293aae229..06b030f468098 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -997,7 +997,7 @@ static bool isVarDeclStrongDefinition(const ASTContext &astContext, return true; if (const auto *rt = varType->getAs<RecordType>()) { - const RecordDecl *rd = rt->getDecl(); + const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf(); for (const FieldDecl *fd : rd->fields()) { if (fd->isBitField()) continue; @@ -2066,8 +2066,10 @@ CharUnits CIRGenModule::computeNonVirtualBaseClassOffset( // Get the layout. const ASTRecordLayout &layout = astContext.getASTRecordLayout(rd); - const auto *baseDecl = cast<CXXRecordDecl>( - base->getType()->castAs<clang::RecordType>()->getDecl()); + const auto *baseDecl = + cast<CXXRecordDecl>( + base->getType()->castAs<clang::RecordType>()->getOriginalDecl()) + ->getDefinitionOrSelf(); // Add the offset. offset += layout.getBaseClassOffset(baseDecl); diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 3e07f6d3e54cc..2084b6d9e8989 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -103,7 +103,8 @@ std::string CIRGenTypes::getRecordTypeName(const clang::RecordDecl *recordDecl, policy.SuppressTagKeyword = true; if (recordDecl->getIdentifier()) - astContext.getRecordType(recordDecl).print(outStream, policy); + QualType(astContext.getCanonicalTagType(recordDecl)) + .print(outStream, policy); else if (auto *typedefNameDecl = recordDecl->getTypedefNameForAnonDecl()) typedefNameDecl->printQualifiedName(outStream, policy); else @@ -138,7 +139,7 @@ isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt, if (!alreadyChecked.insert(rd).second) return true; - const Type *key = cgt.getASTContext().getTagDeclType(rd).getTypePtr(); + const Type *key = cgt.getASTContext().getCanonicalTagType(rd).getTypePtr(); // If this type is already laid out, converting it is a noop. if (cgt.isRecordLayoutComplete(key)) @@ -182,7 +183,8 @@ isSafeToConvert(QualType qt, CIRGenTypes &cgt, // If this is a record, check it. if (const auto *rt = qt->getAs<RecordType>()) - return isSafeToConvert(rt->getDecl(), cgt, alreadyChecked); + return isSafeToConvert(rt->getOriginalDecl()->getDefinitionOrSelf(), cgt, + alreadyChecked); // If this is an array, check the elements, which are embedded inline. if (const auto *at = cgt.getASTContext().getAsArrayType(qt)) @@ -210,7 +212,7 @@ static bool isSafeToConvert(const RecordDecl *rd, CIRGenTypes &cgt) { mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) { // TagDecl's are not necessarily unique, instead use the (clang) type // connected to the decl. - const Type *key = astContext.getTagDeclType(rd).getTypePtr(); + const Type *key = astContext.getCanonicalTagType(rd).getTypePtr(); cir::RecordType entry = recordDeclTypes[key]; // If we don't have an entry for this record yet, create one. @@ -242,7 +244,10 @@ mlir::Type CIRGenTypes::convertRecordDeclType(const clang::RecordDecl *rd) { for (const auto &base : cxxRecordDecl->bases()) { if (base.isVirtual()) continue; - convertRecordDeclType(base.getType()->castAs<RecordType>()->getDecl()); + convertRecordDeclType(base.getType() + ->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf()); } } @@ -275,7 +280,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) { // Process record types before the type cache lookup. if (const auto *recordType = dyn_cast<RecordType>(type)) - return convertRecordDeclType(recordType->getDecl()); + return convertRecordDeclType( + recordType->getOriginalDecl()->getDefinitionOrSelf()); // Has the type already been processed? TypeCacheTy::iterator tci = typeCache.find(ty); @@ -457,7 +463,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) { } case Type::Enum: { - const EnumDecl *ed = cast<EnumType>(ty)->getDecl(); + const EnumDecl *ed = + cast<EnumType>(ty)->getOriginalDecl()->getDefinitionOrSelf(); if (auto integerType = ed->getIntegerType(); !integerType.isNull()) return convertType(integerType); // Return a placeholder 'i32' type. This can be changed later when the @@ -516,7 +523,7 @@ mlir::Type CIRGenTypes::convertTypeForMem(clang::QualType qualType, /// Return record layout info for the given record decl. const CIRGenRecordLayout & CIRGenTypes::getCIRGenRecordLayout(const RecordDecl *rd) { - const auto *key = astContext.getTagDeclType(rd).getTypePtr(); + const auto *key = astContext.getCanonicalTagType(rd).getTypePtr(); // If we have already computed the layout, return it. auto it = cirGenRecordLayouts.find(key); @@ -548,7 +555,7 @@ bool CIRGenTypes::isZeroInitializable(clang::QualType t) { } if (const RecordType *rt = t->getAs<RecordType>()) { - const RecordDecl *rd = rt->getDecl(); + const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf(); return isZeroInitializable(rd); } @@ -623,8 +630,10 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) { // declaration of enums, and C doesn't allow an incomplete forward // declaration with a non-default type. assert( - !typeCache.count(ed->getTypeForDecl()) || - (convertType(ed->getIntegerType()) == typeCache[ed->getTypeForDecl()])); + !typeCache.count( + ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()) || + (convertType(ed->getIntegerType()) == + typeCache[ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()])); // If necessary, provide the full definition of a type only used with a // declaration so far. assert(!cir::MissingFeatures::generateDebugInfo()); @@ -639,7 +648,7 @@ void CIRGenTypes::updateCompletedType(const TagDecl *td) { // Only complete if we converted it already. If we haven't converted it yet, // we'll just do it lazily. - if (recordDeclTypes.count(astContext.getTagDeclType(rd).getTypePtr())) + if (recordDeclTypes.count(astContext.getCanonicalTagType(rd).getTypePtr())) convertRecordDeclType(rd); // If necessary, provide the full definition of a type only used with a diff --git a/clang/lib/CIR/CodeGen/TargetInfo.cpp b/clang/lib/CIR/CodeGen/TargetInfo.cpp index d2d32bbd9403c..1447dba87db7e 100644 --- a/clang/lib/CIR/CodeGen/TargetInfo.cpp +++ b/clang/lib/CIR/CodeGen/TargetInfo.cpp @@ -10,7 +10,7 @@ bool clang::CIRGen::isEmptyRecordForLayout(const ASTContext &context, if (!rt) return false; - const RecordDecl *rd = rt->getDecl(); + const RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf(); // If this is a C++ record, check the bases first. if (const CXXRecordDecl *cxxrd = dyn_cast<CXXRecordDecl>(rd)) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits