From 7ff3eba83e0e1e0a9cb30d84974d5e1066fd5f39 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 14 Mar 2017 04:00:52 +0000 Subject: [PATCH] [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded correctly. This fixes PR30413. Patch by David Lobron. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297702 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCGNU.cpp | 2 +- test/CodeGenObjC/ivar-type-encoding.m | 35 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenObjC/ivar-type-encoding.m diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index ce39bd1c94..9f6ccb4b5d 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -2207,7 +2207,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) { IvarNames.push_back(MakeConstantString(IVD->getNameAsString())); // Get the type encoding for this ivar std::string TypeStr; - Context.getObjCEncodingForType(IVD->getType(), TypeStr); + Context.getObjCEncodingForType(IVD->getType(), TypeStr, IVD); IvarTypes.push_back(MakeConstantString(TypeStr)); // Get the offset uint64_t BaseOffset = ComputeIvarBaseOffset(CGM, OID, IVD); diff --git a/test/CodeGenObjC/ivar-type-encoding.m b/test/CodeGenObjC/ivar-type-encoding.m new file mode 100644 index 0000000000..ffa5e0d7af --- /dev/null +++ b/test/CodeGenObjC/ivar-type-encoding.m @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -S -emit-llvm -fobjc-runtime=gcc -o - %s | FileCheck %s + +@protocol NSCopying +@end + +@interface NSObject { + struct objc_object *isa; +} ++ (id) new; +- (id) init; +@end + +@interface NSString : NSObject ++ (NSString *)foo; +@end + +@interface TestClass : NSObject { +@public + NSString *_stringIvar; + int _intIvar; +} +@end +@implementation TestClass + +@end + +int main() { + TestClass *c = [TestClass new]; + return 0; +} + +// CHECK: @0 = private unnamed_addr constant [12 x i8] c"_stringIvar\00" +// CHECK: @1 = private unnamed_addr constant [12 x i8] c"@\22NSString\22\00" +// CHECK: @2 = private unnamed_addr constant [9 x i8] c"_intIvar\00" +// CHECK: @3 = private unnamed_addr constant [2 x i8] c"i\00" -- 2.40.0