[PATCH] D38774: [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 25 16:24:02 PDT 2017
vsapsai updated this revision to Diff 120337.
vsapsai added a comment.
- Address rjmccall review comment about nested arrays.
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
+ at interface FlexibleArrayMember {
+ char flexible_array[][4][2];
+}
+ 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"^[4[2c]]\00"
+
+
+typedef char FlexibleArray[];
+
+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
@@ -5084,6 +5084,11 @@
// Drill down into arrays.
uint64_t numElts = 1;
+ if (auto arrayType = CGM.getContext().getAsIncompleteArrayType(fieldType)) {
+ numElts = 0;
+ fieldType = arrayType->getElementType();
+ }
+ // Unlike incomplete arrays, constant arrays can be nested.
while (auto arrayType = CGM.getContext().getAsConstantArrayType(fieldType)) {
numElts *= arrayType->getSize().getZExtValue();
fieldType = arrayType->getElementType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38774.120337.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171025/a568f997/attachment.bin>
More information about the cfe-commits
mailing list