From 17c1a2e748d49d293c9926eeeb85aa4890182106 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 15 Feb 2013 21:14:50 +0000 Subject: [PATCH] objective-C: Fixes a compiler crash when encoding an ivar of type pointer to a typedef'ed object. // rdar://13190095 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175298 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 3 ++- lib/AST/ASTContext.cpp | 14 ++++++++++---- test/CodeGenObjC/encode-test-6.m | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 0e8f2b61a4..4cc372363a 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -2119,7 +2119,8 @@ private: bool EncodingProperty = false, bool StructField = false, bool EncodeBlockParameters = false, - bool EncodeClassNames = false) const; + bool EncodeClassNames = false, + bool EncodePointerToObjCTypedef = false) const; // Adds the encoding of the structure's members. void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index bdb464c531..62fd9da1b4 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4994,7 +4994,8 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, bool EncodingProperty, bool StructField, bool EncodeBlockParameters, - bool EncodeClassNames) const { + bool EncodeClassNames, + bool EncodePointerToObjCTypedef) const { CanQualType CT = getCanonicalType(T); switch (CT->getTypeClass()) { case Type::Builtin: @@ -5244,7 +5245,9 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, if (Field->isBitField()) getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); else - getObjCEncodingForTypeImpl(Field->getType(), S, false, true, FD); + getObjCEncodingForTypeImpl(Field->getType(), S, false, true, FD, + false, false, false, false, false, + EncodePointerToObjCTypedef); } S += '}'; return; @@ -5286,14 +5289,17 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, QualType PointeeTy = OPT->getPointeeType(); if (!EncodingProperty && - isa(PointeeTy.getTypePtr())) { + isa(PointeeTy.getTypePtr()) && + !EncodePointerToObjCTypedef) { // Another historical/compatibility reason. // We encode the underlying type which comes out as // {...}; S += '^'; getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, - NULL); + NULL, + false, false, false, false, false, + /*EncodePointerToObjCTypedef*/true); return; } diff --git a/test/CodeGenObjC/encode-test-6.m b/test/CodeGenObjC/encode-test-6.m index 10681dbcc5..b7feb14434 100644 --- a/test/CodeGenObjC/encode-test-6.m +++ b/test/CodeGenObjC/encode-test-6.m @@ -17,3 +17,21 @@ typedef struct {} Z; // CHECK: internal global [14 x i8] c"v16@0:8{?=}16 // CHECK: internal global [26 x i8] c"v32@0:8{?=}16*16{?=}24d24 + +// rdar://13190095 +@interface NSObject @end + +@class BABugExample; +typedef BABugExample BABugExampleRedefinition; + +@interface BABugExample : NSObject { + BABugExampleRedefinition *_property; // .asciz "^{BABugExample=^{BABugExample}}" +} +@property (copy) BABugExampleRedefinition *property; +@end + +@implementation BABugExample +@synthesize property = _property; +@end + +// CHECK: internal global [24 x i8] c"^{BABugExample=@}16 -- 2.40.0