r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 21:00:53 PDT 2017


Author: ahatanak
Date: Mon Mar 13 23:00:52 2017
New Revision: 297702

URL: http://llvm.org/viewvc/llvm-project?rev=297702&view=rev
Log:
[CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded
correctly.

This fixes PR30413.

Patch by David Lobron.

Added:
    cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m
Modified:
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=297702&r1=297701&r2=297702&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Mar 13 23:00:52 2017
@@ -2207,7 +2207,7 @@ void CGObjCGNU::GenerateClass(const ObjC
       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);

Added: cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m?rev=297702&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m (added)
+++ cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m Mon Mar 13 23:00:52 2017
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -S -emit-llvm -fobjc-runtime=gcc -o - %s | FileCheck %s
+
+ at protocol NSCopying
+ at end
+
+ at interface NSObject {
+  struct objc_object *isa;
+}
++ (id) new;
+- (id) init;
+ at end
+
+ at interface NSString : NSObject <NSCopying>
++ (NSString *)foo;
+ at end
+
+ at interface TestClass : NSObject {
+ at public
+  NSString    *_stringIvar;
+  int         _intIvar;
+}
+ at end
+ at implementation TestClass
+
+ at 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"




More information about the cfe-commits mailing list