https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/152845
>From 70a2c652b89a78c361b9df0dd7dc386240492886 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizve...@gmail.com> Date: Sat, 9 Aug 2025 05:46:49 -0300 Subject: [PATCH] [clang] missing changes to the Rewriter This completes https://github.com/llvm/llvm-project/pull/147835 by adapting the changes in the API to the rewriter. Fixes build failures such as reported here: https://github.com/llvm/llvm-project/pull/147835#issuecomment-3170483197 We previously missed this because it was not tested in pre-commit CI. --- .../Frontend/Rewrite/RewriteModernObjC.cpp | 36 +++++++++++-------- clang/lib/Frontend/Rewrite/RewriteObjC.cpp | 24 ++++++++----- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 8f275536b98a6..2b55820b38804 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -852,7 +852,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { IvarT = GetGroupRecordTypeForObjCIvarBitfield(D); if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) { - RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl(); + RecordDecl *RD = IvarT->castAs<RecordType>()->getOriginalDecl(); RD = RD->getDefinition(); if (RD && !RD->getDeclName().getAsIdentifierInfo()) { // decltype(((Foo_IMPL*)0)->bar) * @@ -865,7 +865,8 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) { RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(RecName)); - QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); + QualType PtrStructIMPL = + Context->getPointerType(Context->getCanonicalTagType(RD)); unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *Zero = IntegerLiteral::Create(*Context, @@ -2999,7 +3000,7 @@ QualType RewriteModernObjC::getSuperStructType() { SuperStructDecl->completeDefinition(); } - return Context->getTagDeclType(SuperStructDecl); + return Context->getCanonicalTagType(SuperStructDecl); } QualType RewriteModernObjC::getConstantStringStructType() { @@ -3032,7 +3033,7 @@ QualType RewriteModernObjC::getConstantStringStructType() { ConstantStringDecl->completeDefinition(); } - return Context->getTagDeclType(ConstantStringDecl); + return Context->getCanonicalTagType(ConstantStringDecl); } /// getFunctionSourceLocation - returns start location of a function @@ -3637,7 +3638,8 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, return RewriteObjCFieldDeclType(ElemTy, Result); } else if (Type->isRecordType()) { - RecordDecl *RD = Type->castAs<RecordType>()->getDecl(); + RecordDecl *RD = + Type->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf(); if (RD->isCompleteDefinition()) { if (RD->isStruct()) Result += "\n\tstruct "; @@ -3660,7 +3662,8 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, } } else if (Type->isEnumeralType()) { - EnumDecl *ED = Type->castAs<EnumType>()->getDecl(); + EnumDecl *ED = + Type->castAs<EnumType>()->getOriginalDecl()->getDefinitionOrSelf(); if (ED->isCompleteDefinition()) { Result += "\n\tenum "; Result += ED->getName(); @@ -3732,10 +3735,10 @@ void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDec TagDecl *TD = nullptr; if (Type->isRecordType()) { - TD = Type->castAs<RecordType>()->getDecl(); + TD = Type->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf(); } else if (Type->isEnumeralType()) { - TD = Type->castAs<EnumType>()->getDecl(); + TD = Type->castAs<EnumType>()->getOriginalDecl()->getDefinitionOrSelf(); } if (TD) { @@ -3793,7 +3796,7 @@ QualType RewriteModernObjC::SynthesizeBitfieldGroupStructType( false, ICIS_NoInit)); } RD->completeDefinition(); - return Context->getTagDeclType(RD); + return Context->getCanonicalTagType(RD); } QualType RewriteModernObjC::GetGroupRecordTypeForObjCIvarBitfield(ObjCIvarDecl *IV) { @@ -4572,7 +4575,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get("__block_impl")); - QualType PtrBlock = Context->getPointerType(Context->getTagDeclType(RD)); + QualType PtrBlock = Context->getPointerType(Context->getCanonicalTagType(RD)); // Generate a funky cast. SmallVector<QualType, 8> ArgTypes; @@ -5316,7 +5319,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl"); - QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType castT = + Context->getPointerType(Context->getCanonicalTagType(RD)); FD = SynthBlockInitFunctionDecl(ND->getName()); Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), @@ -5719,7 +5723,10 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { } } } else if (VD->getType()->isRecordType()) { - RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl(); + RecordDecl *RD = VD->getType() + ->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf(); if (RD->isCompleteDefinition()) RewriteRecordBody(RD); } @@ -7460,7 +7467,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { IvarT = GetGroupRecordTypeForObjCIvarBitfield(D); if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) { - RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl(); + RecordDecl *RD = IvarT->castAs<RecordType>()->getOriginalDecl(); RD = RD->getDefinition(); if (RD && !RD->getDeclName().getAsIdentifierInfo()) { // decltype(((Foo_IMPL*)0)->bar) * @@ -7473,7 +7480,8 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { RecordDecl *RD = RecordDecl::Create( *Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(RecName)); - QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); + QualType PtrStructIMPL = + Context->getPointerType(Context->getCanonicalTagType(RD)); unsigned UnsignedIntSize = static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); Expr *Zero = IntegerLiteral::Create(*Context, diff --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp index f49ccf7be68e2..0242fc1f6e827 100644 --- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -2358,7 +2358,7 @@ void RewriteObjC::SynthMsgSendSuperFunctionDecl() { RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get("objc_super")); - QualType argT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType argT = Context->getPointerType(Context->getCanonicalTagType(RD)); assert(!argT.isNull() && "Can't build 'struct objc_super *' type"); ArgTys.push_back(argT); argT = Context->getObjCSelType(); @@ -2401,7 +2401,7 @@ void RewriteObjC::SynthMsgSendSuperStretFunctionDecl() { RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get("objc_super")); - QualType argT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType argT = Context->getPointerType(Context->getCanonicalTagType(RD)); assert(!argT.isNull() && "Can't build 'struct objc_super *' type"); ArgTys.push_back(argT); argT = Context->getObjCSelType(); @@ -2552,7 +2552,7 @@ QualType RewriteObjC::getSuperStructType() { SuperStructDecl->completeDefinition(); } - return Context->getTagDeclType(SuperStructDecl); + return Context->getCanonicalTagType(SuperStructDecl); } QualType RewriteObjC::getConstantStringStructType() { @@ -2585,7 +2585,7 @@ QualType RewriteObjC::getConstantStringStructType() { ConstantStringDecl->completeDefinition(); } - return Context->getTagDeclType(ConstantStringDecl); + return Context->getCanonicalTagType(ConstantStringDecl); } CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor, @@ -3750,7 +3750,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get("__block_impl")); - QualType PtrBlock = Context->getPointerType(Context->getTagDeclType(RD)); + QualType PtrBlock = Context->getPointerType(Context->getCanonicalTagType(RD)); // Generate a funky cast. SmallVector<QualType, 8> ArgTypes; @@ -4468,7 +4468,8 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl"); - QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType castT = + Context->getPointerType(Context->getCanonicalTagType(RD)); FD = SynthBlockInitFunctionDecl((*I)->getName()); Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), @@ -4834,7 +4835,10 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { } } } else if (VD->getType()->isRecordType()) { - RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl(); + RecordDecl *RD = VD->getType() + ->castAs<RecordType>() + ->getOriginalDecl() + ->getDefinitionOrSelf(); if (RD->isCompleteDefinition()) RewriteRecordBody(RD); } @@ -5804,7 +5808,8 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); - QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType castT = + Context->getPointerType(Context->getCanonicalTagType(RD)); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, castT, CK_BitCast, IV->getBase()); @@ -5845,7 +5850,8 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl, SourceLocation(), SourceLocation(), II); assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl"); - QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); + QualType castT = + Context->getPointerType(Context->getCanonicalTagType(RD)); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, castT, CK_BitCast, IV->getBase()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits