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[]; + +@interface FlexibleArrayMember { + FlexibleArray flexible_array; +} +@end +@implementation FlexibleArrayMember +@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; +}; + +@interface VariableSizeIvar { + struct Packet flexible_struct; +} +@end +@implementation VariableSizeIvar +@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
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[]; + +@interface FlexibleArrayMember { + FlexibleArray flexible_array; +} +@end +@implementation FlexibleArrayMember +@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; +}; + +@interface VariableSizeIvar { + struct Packet flexible_struct; +} +@end +@implementation VariableSizeIvar +@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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits