[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 15:42:57 PDT 2017


vsapsai updated this revision to Diff 119952.
vsapsai added a comment.

- Resubmit my last change without files from underlying branch.


https://reviews.llvm.org/D38774

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/ivar-layout-flexible-array.m


Index: clang/test/CodeGenObjC/ivar-layout-flexible-array.m
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjC/ivar-layout-flexible-array.m
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -Wno-objc-root-class -fobjc-arc -emit-llvm -o - %s | FileCheck %s
+
+// rdar://problem/21054495
+typedef char FlexibleArray[];
+
+ at interface FlexibleArrayMember {
+  FlexibleArray flexible_array;
+}
+ at end
+ at implementation FlexibleArrayMember
+ at end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} c"flexible_array\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant {{.*}} c"^c\00"
+
+
+struct Packet {
+  int size;
+  FlexibleArray data;
+};
+
+ at interface VariableSizeIvar {
+  struct Packet flexible_struct;
+}
+ at end
+ at implementation VariableSizeIvar
+ at end
+// CHECK: @OBJC_METH_VAR_NAME_{{.*}} = private unnamed_addr constant {{.*}} c"flexible_struct\00"
+// CHECK-NEXT: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant {{.*}} c"{Packet=\22size\22i\22data\22[0c]}\00"
Index: clang/lib/CodeGen/CGObjCMac.cpp
===================================================================
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -5089,6 +5089,11 @@
     fieldType = arrayType->getElementType();
   }
 
+  if (auto arrayType = CGM.getContext().getAsIncompleteArrayType(fieldType)) {
+    numElts = 0;
+    fieldType = arrayType->getElementType();
+  }
+
   assert(!fieldType->isArrayType() && "ivar of non-constant array type?");
 
   // If we ended up with a zero-sized array, we've done what we can do within


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38774.119952.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171023/800c7c10/attachment.bin>


More information about the cfe-commits mailing list