From 33fa96244135d64e13d964401f3089c251a4aa0b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 28 Jan 2014 20:41:15 +0000 Subject: [PATCH] Objective-C. provide legacy encoding of *id and *Class types instead of crashing. // rdar://15824769. llvm-svn: 200338 --- clang/lib/AST/ASTContext.cpp | 14 +++++++++++++- clang/test/CodeGenObjC/encode-test.m | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index ad3bf5105dd2..9ee624c98b30 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5440,7 +5440,19 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, return; } - case Type::ObjCObject: + case Type::ObjCObject: { + // hack to match legacy encoding of *id and *Class + QualType Ty = getObjCObjectPointerType(CT); + if (Ty->isObjCIdType()) { + S += "{objc_object=}"; + return; + } + else if (Ty->isObjCClassType()) { + S += "{objc_class=}"; + return; + } + } + case Type::ObjCInterface: { // Ignore protocol qualifiers when mangling at this level. T = T->castAs()->getBaseType(); diff --git a/clang/test/CodeGenObjC/encode-test.m b/clang/test/CodeGenObjC/encode-test.m index d6e7b6dfccad..a310a621ecf4 100644 --- a/clang/test/CodeGenObjC/encode-test.m +++ b/clang/test/CodeGenObjC/encode-test.m @@ -169,3 +169,11 @@ const char g11[] = @encode(void); // PR14628 // CHECK: @g12 = constant [3 x i8] c"Ai\00" const char g12[] = @encode(_Atomic(int)); + +// rdar://15824769 +id test_id = 0; +Class test_class = 0; +const char g13[] = @encode(__typeof__(*test_class)); +const char g14[] = @encode(__typeof__(*test_id)); +// CHECK: constant [14 x i8] c"{objc_class=}\00" +// CHECK: constant [15 x i8] c"{objc_object=}\00"