@@ -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
30053006QualType 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\t struct "  ;
@@ -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\t enum "  ;
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
37993802QualType 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,
0 commit comments