From d4c1a2063c83478941fad0a075d225fc66c6d513 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 llvm-svn: 175298 --- clang/include/clang/AST/ASTContext.h | 3 ++- clang/lib/AST/ASTContext.cpp | 14 ++++++++++---- clang/test/CodeGenObjC/encode-test-6.m | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 0e8f2b6..4cc3723 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/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/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index bdb464c..62fd9da 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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/clang/test/CodeGenObjC/encode-test-6.m b/clang/test/CodeGenObjC/encode-test-6.m index 10681db..b7feb14 100644 --- a/clang/test/CodeGenObjC/encode-test-6.m +++ b/clang/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.7.4