Skip to content

Commit a48f8bb

Browse files
mizvekovgithub-actions[bot]
authored andcommitted
Automerge: [clang] missing changes to the Rewriter (#152845)
This completes llvm/llvm-project#147835 by adapting the changes in the API to the rewriter. Fixes build failures such as reported here: llvm/llvm-project#147835 (comment) We previously missed this because it was not tested in pre-commit CI.
2 parents 8a94174 + 34164da commit a48f8bb

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) {
852852
IvarT = GetGroupRecordTypeForObjCIvarBitfield(D);
853853

854854
if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) {
855-
RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl();
855+
RecordDecl *RD = IvarT->castAs<RecordType>()->getOriginalDecl();
856856
RD = RD->getDefinition();
857857
if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
858858
// decltype(((Foo_IMPL*)0)->bar) *
@@ -865,7 +865,8 @@ RewriteModernObjC::getIvarAccessString(ObjCIvarDecl *D) {
865865
RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
866866
SourceLocation(), SourceLocation(),
867867
&Context->Idents.get(RecName));
868-
QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
868+
QualType PtrStructIMPL =
869+
Context->getPointerType(Context->getCanonicalTagType(RD));
869870
unsigned UnsignedIntSize =
870871
static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
871872
Expr *Zero = IntegerLiteral::Create(*Context,
@@ -2999,7 +3000,7 @@ QualType RewriteModernObjC::getSuperStructType() {
29993000

30003001
SuperStructDecl->completeDefinition();
30013002
}
3002-
return Context->getTagDeclType(SuperStructDecl);
3003+
return Context->getCanonicalTagType(SuperStructDecl);
30033004
}
30043005

30053006
QualType RewriteModernObjC::getConstantStringStructType() {
@@ -3032,7 +3033,7 @@ QualType RewriteModernObjC::getConstantStringStructType() {
30323033

30333034
ConstantStringDecl->completeDefinition();
30343035
}
3035-
return Context->getTagDeclType(ConstantStringDecl);
3036+
return Context->getCanonicalTagType(ConstantStringDecl);
30363037
}
30373038

30383039
/// getFunctionSourceLocation - returns start location of a function
@@ -3637,7 +3638,8 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
36373638
return RewriteObjCFieldDeclType(ElemTy, Result);
36383639
}
36393640
else if (Type->isRecordType()) {
3640-
RecordDecl *RD = Type->castAs<RecordType>()->getDecl();
3641+
RecordDecl *RD =
3642+
Type->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf();
36413643
if (RD->isCompleteDefinition()) {
36423644
if (RD->isStruct())
36433645
Result += "\n\tstruct ";
@@ -3660,7 +3662,8 @@ bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
36603662
}
36613663
}
36623664
else if (Type->isEnumeralType()) {
3663-
EnumDecl *ED = Type->castAs<EnumType>()->getDecl();
3665+
EnumDecl *ED =
3666+
Type->castAs<EnumType>()->getOriginalDecl()->getDefinitionOrSelf();
36643667
if (ED->isCompleteDefinition()) {
36653668
Result += "\n\tenum ";
36663669
Result += ED->getName();
@@ -3732,10 +3735,10 @@ void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDec
37323735

37333736
TagDecl *TD = nullptr;
37343737
if (Type->isRecordType()) {
3735-
TD = Type->castAs<RecordType>()->getDecl();
3738+
TD = Type->castAs<RecordType>()->getOriginalDecl()->getDefinitionOrSelf();
37363739
}
37373740
else if (Type->isEnumeralType()) {
3738-
TD = Type->castAs<EnumType>()->getDecl();
3741+
TD = Type->castAs<EnumType>()->getOriginalDecl()->getDefinitionOrSelf();
37393742
}
37403743

37413744
if (TD) {
@@ -3793,7 +3796,7 @@ QualType RewriteModernObjC::SynthesizeBitfieldGroupStructType(
37933796
false, ICIS_NoInit));
37943797
}
37953798
RD->completeDefinition();
3796-
return Context->getTagDeclType(RD);
3799+
return Context->getCanonicalTagType(RD);
37973800
}
37983801

37993802
QualType RewriteModernObjC::GetGroupRecordTypeForObjCIvarBitfield(ObjCIvarDecl *IV) {
@@ -4572,7 +4575,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp
45724575
RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
45734576
SourceLocation(), SourceLocation(),
45744577
&Context->Idents.get("__block_impl"));
4575-
QualType PtrBlock = Context->getPointerType(Context->getTagDeclType(RD));
4578+
QualType PtrBlock = Context->getPointerType(Context->getCanonicalTagType(RD));
45764579

45774580
// Generate a funky cast.
45784581
SmallVector<QualType, 8> ArgTypes;
@@ -5316,7 +5319,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
53165319
RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
53175320
SourceLocation(), SourceLocation(), II);
53185321
assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl");
5319-
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
5322+
QualType castT =
5323+
Context->getPointerType(Context->getCanonicalTagType(RD));
53205324

53215325
FD = SynthBlockInitFunctionDecl(ND->getName());
53225326
Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
@@ -5719,7 +5723,10 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) {
57195723
}
57205724
}
57215725
} else if (VD->getType()->isRecordType()) {
5722-
RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl();
5726+
RecordDecl *RD = VD->getType()
5727+
->castAs<RecordType>()
5728+
->getOriginalDecl()
5729+
->getDefinitionOrSelf();
57235730
if (RD->isCompleteDefinition())
57245731
RewriteRecordBody(RD);
57255732
}
@@ -7460,7 +7467,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
74607467
IvarT = GetGroupRecordTypeForObjCIvarBitfield(D);
74617468

74627469
if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) {
7463-
RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl();
7470+
RecordDecl *RD = IvarT->castAs<RecordType>()->getOriginalDecl();
74647471
RD = RD->getDefinition();
74657472
if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
74667473
// decltype(((Foo_IMPL*)0)->bar) *
@@ -7473,7 +7480,8 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
74737480
RecordDecl *RD = RecordDecl::Create(
74747481
*Context, TagTypeKind::Struct, TUDecl, SourceLocation(),
74757482
SourceLocation(), &Context->Idents.get(RecName));
7476-
QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
7483+
QualType PtrStructIMPL =
7484+
Context->getPointerType(Context->getCanonicalTagType(RD));
74777485
unsigned UnsignedIntSize =
74787486
static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
74797487
Expr *Zero = IntegerLiteral::Create(*Context,

clang/lib/Frontend/Rewrite/RewriteObjC.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ void RewriteObjC::SynthMsgSendSuperFunctionDecl() {
23582358
RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
23592359
SourceLocation(), SourceLocation(),
23602360
&Context->Idents.get("objc_super"));
2361-
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
2361+
QualType argT = Context->getPointerType(Context->getCanonicalTagType(RD));
23622362
assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
23632363
ArgTys.push_back(argT);
23642364
argT = Context->getObjCSelType();
@@ -2401,7 +2401,7 @@ void RewriteObjC::SynthMsgSendSuperStretFunctionDecl() {
24012401
RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
24022402
SourceLocation(), SourceLocation(),
24032403
&Context->Idents.get("objc_super"));
2404-
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
2404+
QualType argT = Context->getPointerType(Context->getCanonicalTagType(RD));
24052405
assert(!argT.isNull() && "Can't build 'struct objc_super *' type");
24062406
ArgTys.push_back(argT);
24072407
argT = Context->getObjCSelType();
@@ -2552,7 +2552,7 @@ QualType RewriteObjC::getSuperStructType() {
25522552

25532553
SuperStructDecl->completeDefinition();
25542554
}
2555-
return Context->getTagDeclType(SuperStructDecl);
2555+
return Context->getCanonicalTagType(SuperStructDecl);
25562556
}
25572557

25582558
QualType RewriteObjC::getConstantStringStructType() {
@@ -2585,7 +2585,7 @@ QualType RewriteObjC::getConstantStringStructType() {
25852585

25862586
ConstantStringDecl->completeDefinition();
25872587
}
2588-
return Context->getTagDeclType(ConstantStringDecl);
2588+
return Context->getCanonicalTagType(ConstantStringDecl);
25892589
}
25902590

25912591
CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavor,
@@ -3750,7 +3750,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) {
37503750
RecordDecl *RD = RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
37513751
SourceLocation(), SourceLocation(),
37523752
&Context->Idents.get("__block_impl"));
3753-
QualType PtrBlock = Context->getPointerType(Context->getTagDeclType(RD));
3753+
QualType PtrBlock = Context->getPointerType(Context->getCanonicalTagType(RD));
37543754

37553755
// Generate a funky cast.
37563756
SmallVector<QualType, 8> ArgTypes;
@@ -4468,7 +4468,8 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
44684468
RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
44694469
SourceLocation(), SourceLocation(), II);
44704470
assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl");
4471-
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
4471+
QualType castT =
4472+
Context->getPointerType(Context->getCanonicalTagType(RD));
44724473

44734474
FD = SynthBlockInitFunctionDecl((*I)->getName());
44744475
Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
@@ -4834,7 +4835,10 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
48344835
}
48354836
}
48364837
} else if (VD->getType()->isRecordType()) {
4837-
RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl();
4838+
RecordDecl *RD = VD->getType()
4839+
->castAs<RecordType>()
4840+
->getOriginalDecl()
4841+
->getDefinitionOrSelf();
48384842
if (RD->isCompleteDefinition())
48394843
RewriteRecordBody(RD);
48404844
}
@@ -5804,7 +5808,8 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
58045808
RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
58055809
SourceLocation(), SourceLocation(), II);
58065810
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
5807-
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
5811+
QualType castT =
5812+
Context->getPointerType(Context->getCanonicalTagType(RD));
58085813
CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, castT,
58095814
CK_BitCast,
58105815
IV->getBase());
@@ -5845,7 +5850,8 @@ Stmt *RewriteObjCFragileABI::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
58455850
RecordDecl::Create(*Context, TagTypeKind::Struct, TUDecl,
58465851
SourceLocation(), SourceLocation(), II);
58475852
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
5848-
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
5853+
QualType castT =
5854+
Context->getPointerType(Context->getCanonicalTagType(RD));
58495855
CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, castT,
58505856
CK_BitCast,
58515857
IV->getBase());

0 commit comments

Comments
 (0)